Created
July 12, 2016 19:02
-
-
Save JackieXu/8a55eba3f9e3b7f0f9519c23b9399689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
def _confidence(ups, downs): | |
n = ups + downs | |
if n == 0: | |
return 0 | |
z = 1.281551565545 | |
p = float(ups) / n | |
left = p + 1/(2*n)*z*z | |
right = z*sqrt(p*(1-p)/n + z*z/(4*n*n)) | |
under = 1+1/n*z*z | |
return (left - right) / under | |
def confidence(ups, downs): | |
if ups + downs == 0: | |
return 0 | |
else: | |
return _confidence(ups, downs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment