Sobes.tech
Middle

How to apply likes and dislikes ratio for ranking answers?

sobes.tech AI

Answer from AI

Several approaches can be used to rank answers based on likes and dislikes, taking into account not only the absolute number but also the ratio between them, as well as statistical significance.

Main methods:

  1. Simple ratio of likes to dislikes — for example, calculating the ratio likes / (likes + dislikes). However, this method does not consider the number of votes and can be unreliable with a small number of ratings.

  2. Wilson score interval — a statistical method that considers the confidence interval for the proportion of positive ratings. It helps rank answers considering the uncertainty with a small number of votes.

  3. Bayesian average — averaging using a prior distribution to avoid overestimating answers with a small number of votes.

  4. Time weighting — considers the freshness of the answer so that newer answers can rise faster in the ranking.

Example of using Wilson score for ranking:

from math import sqrt

def wilson_score(up, down, confidence=0.95):
    n = up + down
    if n == 0:
        return 0
    z = 1.96  # for 95% confidence interval
    phat = up / n
    return (phat + z*z/(2*n) - z * sqrt((phat*(1 - phat) + z*z/(4*n)) / n)) / (1 + z*z/n)

# Example:
likes = 50
dislikes = 10
score = wilson_score(likes, dislikes)
print(score)

Using such methods allows for more objective and stable ranking of answers, considering both quality and the number of ratings.