Posted By

LuckyShot on 03/15/10


php rating voting algorythm stars

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Bayesian Rating - Weighted voted rating system

 / Published in: PHP


Bayesian Rating is using the Bayesian Average. This is a mathematical term that calculates a rating of an item based on the “believability” of the votes. The greater the certainty based on the number of votes, the more the Bayesian rating approximates the plain, unweighted rating. When there are very few votes, the bayesian rating of an item will be closer to the average rating of all items.

  1. $avg_num_votes = 18; // Average number of votes in all products
  2. $avg_rating = 3.7; // Average rating for all products
  3. $this_num_votes = 6; // Number of votes for this product
  4. $this_rating = 4; // Rating for this product
  7. $bayesian_rating = ( ($avg_num_votes * $avg_rating) + ($this_num_votes * this_rating) ) / ($avg_num_votes + $this_num_votes);

Report this snippet  

You need to login to post a comment.