洪水贝叶斯评分创造价值超出范围 [英] Flooding Bayesian rating creates values out of range

查看:212
本文介绍了洪水贝叶斯评分创造价值超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请href="http://www.thebroth.com/blog/118/bayesian-rating" rel="nofollow">贝叶斯评分公式的

I'm trying to apply the Bayesian rating formula, but if I rate 1 out of 5 thousand of hundreds, the final rating is greater than 5.

例如,一个给定的项目没有投票和投票170000次,1星后,其最终得分为5.23。如果我率100,它有一个正常值。

For example, a given item has no votes and after voting 170,000 times with 1 star, its final rating is 5.23. If I rate 100, it has a normal value.

下面是我在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:

Even if I flood with 1 or 2:

$rating_sent = rand(1,2)

在10万票的最终评级是超过5。

The final rating after 100,000 votes is over 5.

我只是做了用一个新的测试

I just did a new test using

$rating_sent = rand(1,5)

10万后,我完全得到了值超出范围范围(10.53)。我知道,在正常情况下没有的项目将获得170000票,而所有其他项目没有得到票。但我不知道是否有什么问题我的code或者如果这是贝叶斯公式考虑到大量选票的预期行为。

And after 100,000 I got a value completely out of range range (10.53). I know that in a normal situation no item will get 170,000 votes while all the other items get no vote. But I wonder if there is something wrong with my code or if this is an expected behavior of Bayesian formula considering the massive votes.

修改

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

Just to make it clear, here is a better explanation for some variables.

$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)。从这里 摘自

The formula is: ( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes). Taken from here

推荐答案

您需要通过total_votes而不是total_items划分时,计算avg_rating。

You need to divide by total_votes rather than total_items when calculating avg_rating.

我所做的更改,并得到了一些表现好多了这里。

I made the changes and got something that behaves much better here.

HTTP://$c$cpad.org/gSdrUhZ2

这篇关于洪水贝叶斯评分创造价值超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆