Created
October 26, 2021 22:24
-
-
Save shinichi-takayanagi/521ca39d8d0b15263fe75cc751b01c61 to your computer and use it in GitHub Desktop.
Snippet for multi-class classification problem using scikit-learn
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.linear_model import LogisticRegression | |
from sklearn.pipeline import make_pipeline | |
from sklearn.model_selection import cross_val_score, StratifiedKFold | |
from sklearn.datasets import make_classification, load_iris | |
from sklearn.metrics import roc_auc_score, make_scorer | |
from sklearn import set_config | |
set_config(display='diagram') | |
pipeline = make_pipeline(LogisticRegression(random_state=0)) | |
pipeline | |
X, y = make_classification(n_samples=100, n_classes = 3, n_features=3, n_redundant=0, n_clusters_per_class=1) | |
cv = StratifiedKFold(n_splits=5) | |
cross_val_score(pipeline, X, y, cv=cv, scoring = make_scorer(roc_auc_score, multi_class='ovr', needs_proba=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment