# Ranking algorthim for views/likes/dislikes

I have a table of data that records the number of views an item receives by users viewing the content and the number of likes and dislikes that the users gave:

ID  Views  Like   Dislikes   Rank
1   1000    100      0
2   1000    100     50
3   500     500      0
4   500     300      0
5   300     300     50


I need to come up with an algorithm that calculates a ranking for each row based upon the number of views, likes and dislikes. The higher the rank, the more important the content is. Items that have higher views and likes but with lower dislikes have a higher rank than those with lower views and lots of dislikes.

The problem I have is that some items with lower views but higher likes would actually be considered much higher value than items that have higher views but a lot of dislikes and as such the item with the lower views should be ranked higher.

How can I accurately calcuate a ranking that takes these three items into account? I am not looking for some solution that would determine a ranking by human subjection but merely an unbiased approach that simply takes imperical values into account.

• You are asking a normative question: which row should get rank 1, given some variables, which one should get rank 2 etc. Empirical data does not help you to answer such a normative question. What you have to do is answer: how many views is a "like" worth? If you can answer that, it is easy to find an algorithm that computes a ranking. In the alternative, you can establish a ranking yourself, and then use statistical methods that find the trade-off for you. One such method is ordered logistic regression. You can then interpolate to new data sets. – Nameless Nov 22 '13 at 13:56
• When you say "how much is a like worth", that would be subjected to human bias, which is what I want to avoid. Giving it some thought, I thought that maybe I could use the number of views as a baseline. The percentage of likes to total likes/dislikes raises or lowers your ranking around this baseline. So if you had 500 views and 500 users liked it, you could get a rank of 1000. But if 500 people disliked it, you would get a rank of zero. Does that make sense? – AndroidDev Nov 22 '13 at 14:07
• No matter how you turn it, you may not be satisfied with a ranking based on your variables. In your example, a row with 1000 views but 500 dislikes and no likes is better ranked than a question with 100 views but 100 likes, even though every visitor liked the latter whereas every second visitor hated the former! You can of course tweak the numbers, but in the end there is always a trade-off between views and likes. And you have to decide which trade-off is most appropriate. – Nameless Nov 22 '13 at 14:15
• But why would you say that an item with 1000 views with 500 dislikes is"better ranked" than something with 500 views with 500 likes? In this example, using strictly my algorithm, the 500 viewed item with 500 likes would get a rank of 1000 but the item with 1000 views with 500 dislikes and no likes would drop to 500 thus making it worse. The only thing I don't like about my algorithm is that it doesn't take the severity into account. For example, an item that has 1 million views but 1 million dislikes is far worse than an item that has 100 views and 100 dislikes. – AndroidDev Nov 22 '13 at 14:56

Ok, so you propose $$index=views+likes-dislikes,$$ but this leads to your severity problem. How do you define severity? Maybe dislikes become worse the more there are (because few dislikes could be mistakes, but many disliked show a pattern). You could evade the problem that "1000 views/1000 dislikes" is equally ranked as "100 views, 100 dislikes" by using an index like $$index=views-(c\cdot dislikes)^d,$$ where $c>0$ is a constant (and probably you want $c<1$), and $d>1$ is another constant. As example, using $c=0.5$ and $d=1.3$, the index for "1000 views, 1000 dislikes" is $-2225$, but for "100 views, 100 dislikes" it is $-62$, so the latter is clearly better. Finding the right constants requires a bit of tweaking, of course. Adding the effect of likes as linear, we get $$index=views-(c\cdot dislikes)^d+e\cdot likes,$$ with $e>0$. Using the latter (general) equation, your idea was the special case $c=1, d=1, e=1$. I think you might solve the severity problem by using $c<1, d>1$ (see example) and some $e>0$; I would advise $e>1$, since a like is probably a better indicator of quality than an additional view without like/dislike. Again, there is no objective standard, so you will have to decide what is appropriate.

Whatever rule you use, for the ranking just order the indices, where higher index is better.

• Looks good except that finding values for c,d,e seems to be black magic. Severity however can be expressed in both a positive or negative way. As an analogy, a guy who climbs 2 meters and falls to the ground is technically worse off by a factor of 2 than someone who climbs only a meter and falls. And someone who climbs 1000 meters and hits the ground is certainly going to get killed and is thus far worse off than someone who only fell 1 meter, probably by a factor of 1000. In the opposite direction, someone with a million views who gets 1 million likes is more severe than 1 view and 1 like. – AndroidDev Nov 22 '13 at 15:44
• You can deal with severity for likes in the same way as dislikes by introducing another constant as exponent, but then you have to find 4 values, and 3 probably already takes some experimentation. ;) – Nameless Nov 22 '13 at 15:50
• I'm certain that it can be done without any constants. If item A has 100 views and 100 likes and no dislikes but item B has 200 views, 100 likes and no dislikes, then item A should have a severity factor of twice that of item B. In other words, it's just a linear calculation where no constants are required. Do you think you can factor that into your equation above without using constants? If you can, I'll mark your answer as accepted. You're really close :-) – AndroidDev Nov 22 '13 at 15:56
• Well sure, your severity factor would just be "likes/views". A has $100/100=1$, B has $100/200=1/2$, so A has twice that of B. But you can't create a ranking just based on this severity factor, as it ignores total views. For example, C with 1000 views and 1000 likes has the same severity factor (by your definition) as A, but it's clearly better. Just adding views doesn't really help, because the severity factor almost has no weight relative to it (takes max value 1). So I think the above approach is more involved, but ultimately better. – Nameless Nov 22 '13 at 16:10
• I wasn't trying to create a ranking based solely upon severity. I just wanted to factor in the severity into index=views+likes−dislikes so that it works in either direction. It just isn't clear to me whether this severity factor is added or multipled to whatever index amounts to or even how to apply that factor. I'm not convinced that c,d,e are required. If item C has 1000 views and 1000 likes, then your right, the severity factor for C should be significantly more. But by how much? – AndroidDev Nov 22 '13 at 16:24

Well the problem depends in which variable is of higher value, views or dislikes. Views is the primary, then what I would do is:

Value of a row = Views * (( likes - dislikes )/ (likes + dislikes))

Then in case of two rows having the same value the row with higher amount of likes would have higher rank.