我正在尝试应用 Bayesian rating formula ,但如果我对 5000 分之 1 进行评分,则最终评分大于 5。
例如,某个项目没有投票,在投票 170,000 次并获得 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)
在 100,000 后,我得到的值完全超出了范围 (10.53)。我知道在正常情况下,没有一个项目会获得 170,000 票,而所有其他项目都不会获得投票。但我想知道我的代码是否有问题,或者考虑到大量选票,这是否是贝叶斯公式的预期行为。
编辑
为了清楚起见,这里对某些变量有更好的解释。
$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
最佳答案
关于algorithm - 洪水贝叶斯评级创建的值超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6011241/