# Voting system flaw

## Recommended Posts

Hey!,

Just looking for some advice on developing a voting/rating algorithm.

What is the most effective way to develop this?

Right now, I am using minimalistic/very simple algorithm, I have two columns: number_of_votes and total_vote, and the score = number_of_votes/total_vote

Problem is, it can be easily skewed if their are a low number of votes (1 vote of 5 will boost the score to 5).

PS: They can vote from 1-5 (the max the score can be is 5)

Thanks guys!

##### Share on other sites

Someone suggest using bayesian algorithm, but I'm not sure how to implant that using my current db structure (without the score going over 5)

Any help or any better way you can think of (to improve upon my current method)?

##### Share on other sites

I don't see anything wrong with your current method. That is generally how all star voting systems work. People vote 1-5 and you display the average of those votes. So what if the first vote is 5 and that boosts it to 5 automatically? That's why you also display the number of votes so people don't get the wrong idea.

##### Share on other sites

I don't see anything wrong with your current method. That is generally how all star voting systems work. People vote 1-5 and you display the average of those votes. So what if the first vote is 5 and that boosts it to 5 automatically? That's why you also display the number of votes so people don't get the wrong idea.

Well I know but say if theirs 1 vote of 5, the score will = 5 (however thats 1 voters opinion which can effect the importance or quality of the content), and if for example I display a 'Top X' based upon their score, they can jump to the list.

I googled around and found the following:

But seems abit too mathematical for me to integrate, so was hoping someone could help me.

##### Share on other sites

Well, then what you're looking for isn't another way to handle star ratings (In fact, any other way would be pretty misleading). Instead, you're looking for a way to rank different entries overall. One such way, as you mentioned in the Bayesian rating system, of which the average star rating is one factor.

Here's an example MySQL implementation of the weighted Bayesian rating system using your current setup:

`SELECT * FROM table ORDER BY (number_of_votes / (number_of_votes + 0) * (total_vote / number_of_votes) + (0 / (number_of_votes + 0)) * (SELECT AVG(total_vote / number_of_votes) FROM table) DESC LIMIT 10`

That should work, but with your current setup I can't think of any way to do it without a subquery. If your database structure was nicer it would be easier. Note that if you want to require a minimum number of votes for it to be selected in the query (and displayed on the top X rated) you'll need to change the 0s in that query to whatever requirement you want.

##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.