Last active
August 14, 2018 17:12
-
-
Save pmbaumgartner/383040487c409a819ecd to your computer and use it in GitHub Desktop.
Making a custom scorer in sklearn that only looks at certain labels when calculating model metrics. For example: This creates a f1_macro scorer object that only looks at the '-1' and '1' labels of a target variable.
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
from sklearn.metrics import f1_score, make_scorer | |
scorer = make_scorer(f1_score, labels=[-1, 1], average='macro') | |
# use like: | |
cv = cross_val_score(model, X, Y, scoring=scorer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment