added weighted average - rScore now uses weighted average
This commit is contained in:
@@ -319,3 +319,15 @@ def my_dict_from_instance(instance,model):
|
||||
thedict[fname] = (verbosename,value)
|
||||
|
||||
return thedict
|
||||
|
||||
def wavg(group, avg_name, weight_name):
|
||||
""" http://stackoverflow.com/questions/10951341/pandas-dataframe-aggregate-function-using-multiple-columns
|
||||
In rare instance, we may not have weights, so just return the mean. Customize this if your business case
|
||||
should return otherwise.
|
||||
"""
|
||||
d = group[avg_name]
|
||||
w = group[weight_name]
|
||||
try:
|
||||
return (d * w).sum() / w.sum()
|
||||
except ZeroDivisionError:
|
||||
return d.mean()
|
||||
|
||||
Reference in New Issue
Block a user