Created
October 13, 2016 22:17
-
-
Save zachwill/e02167ea960d10ba56963fa4c573f9a1 to your computer and use it in GitHub Desktop.
Wilson Score Interval
This file contains hidden or 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): | |
| """ | |
| 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