#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))
Reddit使用Wilson score区间进行注释排序,可以找到解释和python实现here
我认为这个有一个错误的wilson调用,因为如果你有1上0下,你会得到NaN因为你不能对负值做
sqrt
。在查看文章How not to sort by average page中的ruby示例时,可以找到正确的示例:
要获得不带连续性校正的Wilson CI,可以在
statsmodels.stats.proportion
中使用proportion_confint
。要获得具有连续性校正的Wilson CI,可以使用下面的代码。高温高压
相关问题 更多 >
编程相关推荐