
Untitled
By: a guest on
Aug 1st, 2012 | syntax:
None | size: 1.60 KB | hits: 11 | expires: Never
How can I improve this equation so items with more negative votes than positive return a more useful Wilson Score
def ci_lower_bound(pos, n, confidence):
if n==0: return 0
z = 1.96
phat = 1.0*pos/n
score = (phat + z*z/(2*n) - z*math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
return score
import math
def ci_lower_bound(pos, n, neg=0):
if n == 0:
return 0
# Cannot calculate the square-root of a negative number
if pos == 0:
votes, use_neg = neg, True
else:
votes, use_neg = pos, False
# Confidence
z = 1.96
phat = 1.0 * votes / n
# Calculate how confident we are that this is bad or good.
score = (phat + z*z/(2*n) - z * math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
# This relationship is defined above.
# Multiply by -1 to return a negative confidence.
if use_neg:
return -1 * score
return score
import math
def ci_lower_bound(pos, n, neg=0):
if n == 0:
return 0
# Cannot calculate the square-root of a negative number
if pos == 0:
votes, use_neg = neg, True
else:
votes, use_neg = pos, False
# Confidence
z = 1.96
phat = 1.0 * votes / n
# Calculate how confident we are that this is bad or good.
score = (phat + z*z/(2*n) - z * math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
# This relationship is defined above.
# Multiply by -1 to return a negative confidence.
if use_neg:
return -1 * score
return score
>>> sorted([(0,-4000),(1,-4000),(0,-1),(1,-1)])
[(0, -4000), (0, -1), (1, -4000), (1, -1)]