I have the problem specified here. After some research I have found this approach to overcome the issue.
What about having a scaling factor to adjust the impact of quantity (total) of individual ratings as needed? Rough draft:
sort_score = (pos / total) + (W * log(total))Here, W is the weighting (scaling) factor. Total = positive + negative
For example, in this case I have three ratings for the same thing. My implementation for a rating scale of 1 star to 4 stars is:
counter_positive=0
counter_negative=0
total_rating = 0.0
reviews = [(340, Decimal('4.0')), (340, Decimal('4.0')), (340, Decimal('4.0'))]
for s in reviews:
if s[1] > 2.0:
counter_positive+=1
else:
counter_negative+=1
total_rating+=float(s[1])
counter_total = counter_positive + counter_negative
tup = (counter_positive / counter_total) + ((total_rating/len(reviews)) * log(counter_total))
print tup #5.39444915467
Since the result is 5.39444915467 when the scale is <= 4 , certainly I am doing the given implementation wrong. I don't have a math background, so, please be patient.
I came up with this possible solution. Compute your arithmetic average star rating $A$ of a given product, then multiply it by this scaling function,
$$1-\exp\left(-\frac{n^2}{h^2}\right),$$
where $\exp$ is the exponent function, e.g.
Math.exp()in many languages. A product rating $R$ would be calculated as$$R=(1-e^{-n^2/h^2})\times A$$
where $n$ is the number of reviews for that product, and $h$ is a parameter of your choosing, say $h=10$.
The scaling function looks like this:
So as you can see, the lower the number of reviews, the lower the scale factor to $A$. As soon as the number of reviews surpasses a certain number the scaling factor is very close to 1 forever, which will give you the straight arithmetic average.
For example, with $h=10$, for product $P_1$ suppose we have the following product reviews: $$P_1=\{4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4\}$$ with 16 reviews at 4 stars each, giving an arithmetic mean of $A=4$, then $$R=(1-\exp(16^2/10^2))\times 4=3.69078.$$ On the other hand a product $P_2$ with one 5-star review, $P_2=\{5\}$, has an arithmetic mean of $A=5$, and would have the rating $$R=(1-\exp(1^2/10^2))\times 5=0.0497508.$$
You can always round up or down to get a whole number answer if you like.
In code you can use:
where
nis number of product reviews,his a fixed parameter specifying how sensitive the rating system is, andais the arithmetic average of the product. UseMath.floororMath.ceilto round down or up !