UGFraud
UGFraud copied to clipboard
Scale function bug?
Is the else condition indented wrongly?
def scale_value(value_dict):
"""
Calculate and return a dict of the value of input dict scaled to (0, 1)
"""
ranked_dict = [(user, value_dict[user]) for user in value_dict.keys()]
ranked_dict = sorted(ranked_dict, reverse=True, key=lambda x: x[1])
up_max, up_mean, up_min = ranked_dict[0][1], ranked_dict[int(len(ranked_dict) / 2)][1], ranked_dict[-1][1]
scale_dict = {}
for i, p in value_dict.items():
norm_value = (p - up_min) / (up_max - up_min)
if norm_value == 0: # avoid the 0
scale_dict[i] = 0 + 1e-7
elif norm_value == 1: # avoid the 1
scale_dict[i] = 1 - 1e-7
else:
scale_dict[i] = norm_value
return scale_dict