Skip to content

Instantly share code, notes, and snippets.

@lmassaron
Created February 28, 2019 08:48
Show Gist options
  • Select an option

  • Save lmassaron/cac82df412f1ccd143d513902e04c8fb to your computer and use it in GitHub Desktop.

Select an option

Save lmassaron/cac82df412f1ccd143d513902e04c8fb to your computer and use it in GitHub Desktop.
Fast Computation of AUC-ROC score
import numpy as np
from numba import jit
@jit
def fast_auc(y_true, y_prob):
y_true = np.asarray(y_true)
y_true = y_true[np.argsort(y_prob)]
nfalse = 0
auc = 0
n = len(y_true)
for i in range(n):
y_i = y_true[i]
nfalse += (1 - y_i)
auc += y_i * nfalse
auc /= (nfalse * (n - nfalse))
return auc
def eval_auc(preds, dtrain):
labels = dtrain.get_label()
return 'auc', fast_auc(labels, preds), True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment