阅读How Not to Sort by Average Rating之后,我很好奇是否有人对Bernoulli参数使用了Wilson得分下限置信区间的Python实现?
最佳答案
Reddit使用Wilson得分区间进行评论排名,可以在here中找到解释和python实现
#Rewritten code from /r2/r2/lib/db/_sorts.pyx
from math import sqrt
def confidence(ups, downs):
n = ups + downs
if n == 0:
return 0
z = 1.0 #1.44 = 85%, 1.96 = 95%
phat = float(ups) / n
return ((phat + z*z/(2*n) - z * sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n))