algorithm used to calculate 5 star ratings

2019-03-07 12:49发布

I need to calculate 5-star ratings like the one on Amazon website. I have done enough search to find what is the best algorithm, but I am not able to get a proper answer. For example, if these are the ratings

5 star - 252
4 star - 124
3 star - 40
2 star - 29
1 star - 33

totally 478 reviews

Amazon has calculated this to be "4.1 out of 5 stars". Can anyone tell me how this figure is arrived at? I am not able to get this just by doing average.

9条回答
别忘想泡老子
2楼-- · 2019-03-07 13:24

Yes, you can average them out:

(5 * 252 + 4 * 124 + 3 * 40 + 2 * 29 + 1 * 33) / 478 = 4.11

查看更多
孤傲高冷的网名
3楼-- · 2019-03-07 13:29

This rating system is based on a weighted average or weighted mean. That is, they used the weight in terms of stars to compute a decimal value which rounds to 4.1. For example:

Sum of (weight * number of reviews at that weight) / total number of reviews
(5*252 + 4*124 + 3*40 + 2*29 + 1*33) / 478 = 4.1
查看更多
叼着烟拽天下
4楼-- · 2019-03-07 13:29

You may want to check this algorithm out: Calculating Average Rating the Right Way using PHP and MySQL - there's no need of saving each "star" (aka rating grade) and its corresponding number of votes and then having to retrieve thousands of rows from the database every time you need to calculate their average. (unless you want to display exactly how many people rated the given item with 1, 2, 3, 4 & 5 stars)

查看更多
【Aperson】
5楼-- · 2019-03-07 13:31

If you are start calculation of overall rating from beginning then this formula will help you.

Formula

((Overall Rating * Total Rating) + new Rating) / (Total Rating + 1)

Example

suppose you have no ratings till now then formula is like, overall rating is "0" till now. total rating "0" and given rating is "4"

((0*0)+4)/1 = 4

If overall rating is "4.11" Total rating is "478" And new rating giving by one user is "2"

then formula is like

((4.11 * 478)+ 2)/479 // 479 is increment of new rating from 478
查看更多
家丑人穷心不美
6楼-- · 2019-03-07 13:34

That's a weighted average, where you weigh each rating with the number of votes it got:

(5*252 + 4*124 + 3*40 + 2*29 + 1*33) / (252+124+40+29+33) = 4.11 and change
查看更多
可以哭但决不认输i
7楼-- · 2019-03-07 13:36

There is a really great write up on this topic at evanmiller.org. He goes through and discusses the pros and cons of a few approaches and suggests a mathematically reliable way of weighting and calculating votes.

http://evanmiller.org/ranking-items-with-star-ratings.html

查看更多
登录 后发表回答