2011-05-15 37 views
2

我试图以应用Bayesian rating formula,但如果我评级1 5000数百名,最终评级是大于5洪水贝叶斯评分创造价值超出范围

例如,一个给定的项目没有投票,经过投票17万次,1星,最终评分为5.23。如果我评价为100,则它具有正常值。

这是我在PHP中的。

<?php 
// these values came from DB 
$total_votes  = 2936; // total of votes for all items 
$total_rating = 582.955; // sum of all ratings 
$total_items  = 202; 

// now the specific item, it has no votes yet 
$this_num_votes = 0; 
$this_score  = 0; 
$this_rating  = 0; 

// simulating a lot of votes with 1 star 
for ($i=0; $i < 170000; $i++) { 
    $rating_sent = 1; // the new rating, always 1 

    $total_votes++; // adding 1 to total 
    $total_rating = $total_rating+$rating_sent; // adding 1 to total 

    $avg_num_votes = ($total_votes/$total_items); // Average number of votes in all items 
    $avg_rating = ($total_rating/$total_items); // Average rating for all items 
    $this_num_votes = $this_num_votes+1;   // Number of votes for this item 
    $this_score = $this_score+$rating_sent;  // Sum of all votes for this item 
    $this_rating = $this_score/$this_num_votes; // Rating for this item 

    $bayesian_rating = (($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating))/($avg_num_votes + $this_num_votes); 
} 
echo $bayesian_rating; 
?> 

即使我用1或2泛滥:

$rating_sent = rand(1,2) 

最终的评价后10万次投票是在5

我只是做了使用

$rating_sent = rand(1,5) 
新的考验

而且在10万之后,我的数值完全超出了范围(10.53)。我知道,在正常情况下,没有项目会获得17万张选票,而其他所有项目都不会获得投票。但是我想知道我的代码是否有问题,或者如果这是考虑到大量投票的贝叶斯公式的预期行为。

编辑

只是为了说清楚,这里是一些变量更好的解释。

$avg_num_votes // SUM(votes given to all items)/COUNT(all items) 
$avg_rating  // SUM(rating of all items)/COUNT(all items) 
$this_num_votes // COUNT(votes given for this item) 
$this_score  // SUM(rating for this item) 
$bayesian_rating // is the formula itself 

的公式为:((avg_num_votes * avg_rating) + (this_num_votes * this_rating))/(avg_num_votes + this_num_votes)。取自here

+0

你用来计算'$ bayesian_rating'变量的值? '$ avg_num_votes'等。 – Ishtar 2011-05-15 21:46:11

+0

我编辑了这个问题,为一些变量添加了更好的解释。我开始认为,当一个项目获得太多票数而其他项目没有得到新票时,这个项目的评级往往是无限的。 – rlcabral 2011-05-15 22:12:52

+0

但是,实际值是什么?你能打印它们吗? – Ishtar 2011-05-15 22:24:49

回答

3

计算avg_rating时,需要除以total_votes而不是total_items。

我做了修改,并得到了一些在这里表现好得多的东西。

http://codepad.org/gSdrUhZ2

+0

好主人...... 2小时看着这个,并没有看到。刚刚好!谢谢。 – rlcabral 2011-05-15 22:29:17