Last active
October 1, 2020 12:58
-
-
Save xiaowei1234/4577e62970dc0f9425e00b238e3f5b96 to your computer and use it in GitHub Desktop.
binary classification scorers
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 | |
import pandas as pd | |
from scipy.stats import ks_2samp | |
from sklearn.metrics import make_scorer, roc_auc_score, log_loss | |
from sklearn.model_selection import GridSearchCV | |
def ks_stat(y, yhat): | |
return ks_2samp(yhat[y==1], yhat[y!=1]).statistic | |
ks_scorer = make_scorer(ks_stat, needs_proba=True) | |
log_scorer = make_scorer(roc_auc_score, needs_proba=True, greater_is_better=False) | |
roc_scorer = make_scorer(log_loss, needs_proba=True) | |
grid = GridSearchCV(pl, param_grid=param_grid, scoring={'auc': roc_scorer, 'log': log_scorer} | |
, refit='log') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment