-1

I'm working on code where a star rating system was implemented, allowing users to rate between 1 & 5 stars. Instead of displaying an item's actual rating it uses this algorithm:

( rating_votes / ( rating_votes+10 ) ) * ( rating_total/rating_votes ) ) + ( 10 / ( rating_votes+10 ) ) * 4

Based on my intuition it seems like the intent of this is to default the rating to "4 stars" and to not drop the rating too quickly when there's under 10 votes.

Does anyone know what the mathematical name of this algorithm is called? Also can it's implementation be simplified and still produce the same output?

andand
  • 17,134
  • 11
  • 53
  • 79
Josh Ribakoff
  • 2,948
  • 3
  • 27
  • 26

3 Answers3

6

This is known as a "Bayesian average", a variant of additive smoothing. The basic idea is, you front-load a new estimator with a prior estimate of what the "real" average probably is, and then additional votes are added to that existing evidence. It means that it takes a lot of votes to move the average up or down.

And yes, its implementation can be simplified. See https://en.wikipedia.org/wiki/Bayesian_average for the basic formula.

Sneftel
  • 40,271
  • 12
  • 71
  • 104
6

I got:

(rating_votes / ( rating_votes +10 )) * ( rating_total / rating_votes ) + 
( 10 / ( rating_votes +10 ) ) *4 

= (rating_total / (rating_votes + 10)) + (40 / (rating_votes + 10))

= (rating_total + 40) / (rating_votes + 10)

... you seem to have missed an opening bracket but is that what you meant? If so then your intuition is correct — it pretends that 10 people voted '4' before anyone else jumped in.

Other than integer rounding, depending on your language, simplification should produce the same result.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • I looped through all our content/ratings and compared your 1st line to the 3rd line, and they do indeed produce the same output when rounded to a handful (10) decimal places. – Josh Ribakoff May 27 '14 at 23:31
  • 1
    Very nice way of simplifying the equation - and representing the concept as "start with ten votes of 4". – Floris May 28 '14 at 01:08
4

You are right - the final rating can be rewritten as

final = (1-f) * rating + f * 4

Where the factor f decides how much the "actual" rating matters vs the "default" of 4.

Now you just have to convince yourself that f can be written as

f =  10 / (votes + 10)
Floris
  • 45,857
  • 6
  • 70
  • 122