Skip to content

Instantly share code, notes, and snippets.

@sswt
Created January 23, 2017 19:59
Show Gist options
  • Save sswt/d229aad3612c5144e2abd38bb7997062 to your computer and use it in GitHub Desktop.
Save sswt/d229aad3612c5144e2abd38bb7997062 to your computer and use it in GitHub Desktop.
Outbrain map@12 evaluation
def eval_map(yhat, dtrain):
inds = (-yhat).argsort(kind='mergesort')
X = np.vstack([dtrain.data['display_id'], dtrain.get_label()]).T
X = X[inds[X[inds, 0].argsort(kind='mergesort')]]
y_ind = np.where(X[:, 1] == 1)[0]
y_pr = np.unique(X[:, 0], return_index=True)[1]
return 'map@12_ob', np.mean(1 / (y_ind - y_pr + 1)), True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment