Created
February 28, 2019 08:48
-
-
Save lmassaron/cac82df412f1ccd143d513902e04c8fb to your computer and use it in GitHub Desktop.
Fast Computation of AUC-ROC score
This file contains hidden or 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
| 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