click/all = 1/2 > 9/20
p —— click/all
n —— all
z —— 正态分布,均值 + z * 标准差 置信度。 z = 1.96,置信度为95%
def wilson(click, all):
if all == 0:
return 0
z = 1.96
r = 1.0* click / all
n = 1.0 + (z*z/all)
z1 = r + z*z/(2*all)
z2 = z * sqrt(r*(1.0-r)/all + z*z/(4.0*all*all))
return (z1-z2)/n, (z1+z2)/n
纠正点击率取下限(z1-z2)/n