Skip to content

Instantly share code, notes, and snippets.

@shinichi-takayanagi
Created October 26, 2021 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinichi-takayanagi/521ca39d8d0b15263fe75cc751b01c61 to your computer and use it in GitHub Desktop.
Save shinichi-takayanagi/521ca39d8d0b15263fe75cc751b01c61 to your computer and use it in GitHub Desktop.
Snippet for multi-class classification problem using scikit-learn
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