Last active
June 17, 2020 17:36
-
-
Save wmelton/edf861809e2c78a33235f50170c159ab to your computer and use it in GitHub Desktop.
Rank by PDF
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
import math | |
def rankByPDF(alpha, beta): | |
mu = alpha / (alpha + beta) | |
std_error = 1.65 * math.sqrt( (alpha * beta) / ( ( (alpha + beta)**2) * (alpha + beta + 1) ) ) | |
return mu - std_error | |
## | |
## Property A: 20 5-Stars and 2 1-Stars | |
## Alpha = 1 + (20 * 1) + (2 * 0.2) = 21.4 | |
## Beta = Alpha - 22 (count of all reviews) = 1.6 | |
## | |
print "Property A: " + str( rankByPDF(21.4, 1.6) ) | |
## | |
## Property B: 6 5-Stars and 1 3-Stars | |
## Alpha = 1 + (6 * 1) + (1 * 0.6) = 7.2 | |
## Beta = Alpha - 7 (count of all reviews) = 0.8 | |
## | |
print "Property B: " + str( rankByPDF(7.2, 0.8) ) | |
## Output | |
## Property A: 0.844747303679 | |
## Property B: 0.735 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment