Last active
August 29, 2015 14:04
-
-
Save iamaziz/3e42647e9e007084944a to your computer and use it in GitHub Desktop.
Calculate the evaluation metric "AMS" of Higgs Boson competition at Kaggle https://www.kaggle.com/c/higgs-boson/details/evaluation
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
# Calculate the evaluation metric "AMS" of Higgs Boson competition at Kaggle | |
# https://www.kaggle.com/c/higgs-boson/details/evaluation | |
""" | |
__Author__ = "Aziz Alto" | |
""" | |
import numpy as np | |
import pandas as pd | |
# input solution and predicted result files | |
true_sol = './solution.csv' # assumes columns: EventId, Class, Weight | |
pred_res = './result.csv' # assumes columns: EventId, RankOrder, Class | |
# read files | |
sol = pd.read_csv(true_sol) | |
res = pd.read_csv(pred_res) | |
# read Weight 'w' and Class(label) 'y' of the true solution | |
w = sol.Weight.values | |
y = sol.Class.values | |
# read predicted Class(label) 'p' of the result | |
p = res.Class.values | |
# sum up weights of s (True Positive) and b (Flase Positive) | |
s, b = 0, 0 # initialize s and b | |
for w, y, p in zip(w, y, p): | |
if (y == p == 's'): | |
s += w # s = sum(w_i * (y_i == 's') * (y^_i == 's')) | |
elif (y == 'b') and (p == 's'): | |
b += w # b = sum(w_i * (y_i == 'b') * (y^_i == 's')) | |
# calculate AMS | |
def ams(s, b, b_r=10): | |
""" b_r: constant regularization term """ | |
a = np.sqrt( 2 * ( (s + b + b_r) * np.log ( 1 + s / (b + b_r) ) - s ) ) | |
return a | |
print("s: {}, b: {}".format(s, b)) | |
print("AMS: {}".format(ams(s, b))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment