# Average in a rating between 1 and 5

A user can vote on these numbers:

1, 2, 3, 4, 5


Then it's displayed as groups like this:

1 - 5 votes
2 - 3 votes
3 - 1 vote
4 - 17 votes
5 - 2 votes


Now I want the avarage rating score, like 3.9 or whatever it will be.

What I tried and failed:

Multiply all rows in the groups like:

1 - 1 * 5 votes
2 - 2 * 3 votes
3 - 3 * 1 vote
4 - 4 * 17 votes
5 - 5 * 2 votes


and then a sum of them where I get 52. Then I divide it with 15 which is the sum of all the valid scores. 52/15 = 3.46.

If I do that with the same votes on each, I can see how this is not correct:

1 - 1 * 1 votes
2 - 2 * 1 votes
3 - 3 * 1 vote
4 - 4 * 1 votes
5 - 5 * 1 votes


The result with my way would be 15/15 and that's 1 but it should be 3 in this case.

Any ideas?

• Why the downvotes? The OP is wrestling with a problem that's hard (unless you happen to know the answer) so asked for help here. Aug 31 '16 at 13:12
• The product $4\cdot 17=68$, so I don't see how you get a sume of $52$. Aug 31 '16 at 13:28
• Also, why are you dividing by $1+2+3+4+5$ rather than the number of votes? Aug 31 '16 at 13:30
• Great question. It's only easy when you know how! Aug 31 '16 at 14:10
• BTW, note that the raw average rating can be a rather poor quality measure in practice, especially when the number of votes is low. For example, most people would intuitively consider 99 5-star ratings and one 4-star rating (average 4.99) to be a far better sign of high quality than just a single 5-star rating (average 5.0), because the latter is only based on one person's opinion and thus has very little predictive value. One way to address this issue is to include some pseudocounts in your average score calculation. Aug 31 '16 at 16:33

I don't know where you pulled that $15$ denominator, but you're trying to do the weighted average. If you have a bunch of values $a_i$ to take the average from, all with a importance weight $w_i$, the weighted average is defined as follows : $$\frac{ \sum_{i = 1}^n w_i \cdot a_i }{ \sum_{i = 1}^n w_i }$$

Note that the weights used in the numerator must be the same as the weights used in the denominator. In your problem the $a_i$ are the possible scores to give and the $w_i$ are the number of persons that gave that score. In your first case you get, $$\frac{ 1\cdot5+2\cdot3+3\cdot1+4\cdot17+5\cdot2 }{ 5 + 3 + 1 + 17 + 2 } = \frac{92}{28}$$

In the second case, you get $$\frac{ 1+2+3+4+5 }{ 1+1+1+1+1 } = \frac{15}{5} = 3$$

• $15 = 1 + 2 + 3 + 4 + 5 = \sum_i a_i$. The OP was so close to the correct formula. Aug 31 '16 at 13:23

Everybody is showing you how to compute the weighted average, but not why.

What you have is 28 votes. The average of 28 values is the sum of those values, divided by 28. In this case, that means:

$$\frac{1+1+1+1+1+2+2+2+3+4+\cdots+4+5+5}{28}$$

This, we see, is the same as:

$$\frac{1\cdot 5 + 2\cdot 3+ 3\cdot 1 + 4\cdot 17+5\cdot 2}{28}$$

• I joined this community just to upvote this answer! This is the only answer here which pitches itself at the right level, and shows in layman's terms where the weighted average comes from. Perfect. Aug 31 '16 at 14:09

You should divide by the total number of voters, not the total of the scores: $$\bar{x}=\frac{5\cdot1+3\cdot2+1\cdot3+17\cdot4+2\cdot5}{5+3+1+17+2}$$ $$=\frac{92}{28}\approx 3.29$$

To see why this is reasonable, suppose everyone voted for the same number (say $2$). Then you would certainly want the average to come out as $2$. It won't if you compute it your way.

Generally, if $v_i$ votes are cast for the score $s_i$, then the average score is $$\bar{s} = \frac{v_1s_1+v_2s_2+\cdots+v_ns_n}{v_1+v_2+\cdots+v_n}$$ This is called a weighted average; each score is weighted by the number of votes for it, then the weighted scores are added and the sum divided by the total of the weights. A bigger number of votes for a particular score gives the score more prominence in the average.

Addendum: Another way to look at the weighted average is to just rewrite it as $$\bar{s} = (\tfrac{v_1}{v_1+v_2+\cdots+v_n})s_1 + (\tfrac{v_2}{v_1+v_2+\cdots+v_n})s_2 + \cdots + (\tfrac{v_n}{v_1+v_2+\cdots+v_n})s_n$$ Here you can see that each score is weighted by the fraction of votes it got out of the total. Each of the weights is between 0% and 100% and they add up to 100%. So the weighted average will be somewhere between the smallest and the largest score.

I think what you want is the weighted average, and you've almost correctly invented it.

The formula is (total point sum)/(number of voters). In your example it's $$\frac{1 \times 5 + 2 \times 3 + 3 \times 1 + 4 \times 17 + 5 \times 2} {5 + 3 + 1 + 17 + 2} .$$

See

https://en.wikipedia.org/wiki/Weighted_arithmetic_mean

and

http://www.rapidtables.com/calc/math/weighted-average-calculator.htm

In your first example you should calculate;

$$\dfrac{1\cdot5+2\cdot3+3\cdot1+4\cdot17+5\cdot2}{5+3+1+17+2}$$ $$=\dfrac{92}{28}\approx3.29$$

You always divide by the total number of votes, so in the second case you get $\frac{15}{5}=3$, like you expected.

In your first example I get $\frac{92}{28}=3.29$.

You should not divide by $15$, but by the number of votes. In your case, the pondered sum is 90 (and not 52) and once you divide it by your 28 votes, you get an average note of about 3.2

Your scenario : - 1 - 1 * 5 votes 2 - 2 * 3 votes 3 - 3 * 1 vote 4 - 4 * 17 votes 5 - 5 * 2 votes

Your to total number of votes casted are :- 5+3+1+17+2 = 28

so my friend to calculate the correct average divisor has to be 28 Now just add all up - 1*5 + 2*3 + 3*1 + 4*17 + 5*2 = 92

So you average rating is 92/28