ベイジアン評価式を適用しようとしていますが、5000のうち1を評価すると、最終的な評価は5より大きくなります。
たとえば、特定のアイテムには投票がなく、1つ星で170,000回投票した後、最終的な評価は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)
100,000票後の最終評価は5を超えています。
を使用して新しいテストを行いました
$rating_sent = rand(1,5)
そして、100,000を超えると、完全に範囲外の値(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)
です。ここから撮影