Last active
October 6, 2017 17:52
-
-
Save jaradc/9ae050e6ca04102388538f7bfee237d0 to your computer and use it in GitHub Desktop.
Create a custom scorer in sklearn
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
def specificity_scorer(y_true, y_pred): | |
tn, fp, fn, tp = metrics.confusion_matrix(y_true, y_pred).ravel() | |
return tn / (tn+fp) | |
specificity = metrics.make_scorer(specificity_scorer, greater_is_better=True) | |
# use in cross_val_score | |
cv = cross_val_score(xgb, dt.features_.values, y, scoring=specificity, cv=5, verbose=2) | |
# use in GridSearchCV | |
grid = GridSearchCV(clf, {}, scoring=specificity) | |
grid.fit(X_train, y_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment