Skip to content

Instantly share code, notes, and snippets.

@zachwill
Created October 13, 2016 22:17
Show Gist options
  • Select an option

  • Save zachwill/e02167ea960d10ba56963fa4c573f9a1 to your computer and use it in GitHub Desktop.

Select an option

Save zachwill/e02167ea960d10ba56963fa4c573f9a1 to your computer and use it in GitHub Desktop.
Wilson Score Interval
from math import sqrt
def confidence(ups, downs):
"""
Wilson Score Interval: http://stackoverflow.com/questions/10029588
"""
n = ups + downs
if n == 0:
return 0
# 1.44 = 85%, 1.96 = 95%
z = 1.64
phat = float(ups) / n
return ((phat + z * z / (2 * n) - z * sqrt((phat * (1 - phat) + z * z / (4 * n)) / n)) / (1 + z * z / n))
print confidence(9, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment