views:

81

answers:

2

I want to implement a 5 star rating system on my site, and i have been trying use the bayesian rating algorithm explained here and here with no success. This is my scenario;

I have three items (A, B and C) that need to be rated by a vote of 1 for an UP vote and a 0 for DOWN vote. In the database i have the following;

Sum(A) = 500 UP out of 1000 votes Sum(B) = 0 out of 1000 votes Sum(C) = 0 out of 1000 votes

Total Count of Votes in the database for all items = 3000

How do i calculate the bayesian rating/weight(br) for each item?

How do i rate this items with a weighting system of 1 - 5?

Gath

+1  A: 

Simple Algebra:

AvgVotes = Sum of all votes / Sum of all items

AvgRating = Sum of up votes for all items * 5 / Sum of all votes

CurVotes = Number of votes on current item

CurRating = Sum of up votes on current item * 5/ Number of votes on current item

TotalVotes = Sum of all votes + Sum of votes on current item

((AvgVotes * AvgRating) + (CurVotes * CurRating)) * 5 / TotalVotes

So plugging in your numbers evaluating the weight for A...

AvgVotes = 1000

AvgRating = 0 (Remember do not include numbers for the item you are evaluating in this calculation)

CurVotes = 1000

CurRating = 500 * 5 / 1000 = 2.5

Total Votes = 2000 + 1000 = 3000

((1000 * 0) + (1000 * 2.5)) * 5 / 3000 = 4.166

I forgot to add, do NOT include any items in any calculation or sum above that have no votes or it will throw the weights off.

EDIT - Simplified Solution:

I should note that there is a simplified solution to the problem that can be performed. I only demonstrated longhand form for comprehension. The compressed algorithm looks like:

Definitions:

SET = Anything not related to the current evaluation target where votes is greater than zero.

TARGET = The element you are currently trying to evaluate

25*(((Sum of SET up-votes)/(Sum of SET items)) + (Sum of TARGET up-votes)) / (Sum of TARGET votes + Sum of SET votes)

Again plugging in with your numbers evaluating 'A' for clarification and proof:

(25*((0/2)+500)) / (1000+2000) = 4.166

Peter Hanneman
I moved my comment into my edited post above for easier reading.
Peter Hanneman
+1  A: 

This blog post, How Not To Sort By Average Rating, describes exactly your situation, and how to solve it using a Wilson Score confidence interval. Reddit used this to good effect.

Nick Johnson