首页 > 解决方案 > scikit-learn:plot_roc_curve 以管道作为估计器

问题描述

有没有办法使用带有管道的 plot_roc_curve 作为估计器?我是说:

plot_roc_curve(pipeline, X_test, y_test)

标签: pythonscikit-learnpipelineroc

解决方案


使用 scikit-learn 0.22,它就像一个魅力。

from sklearn.datasets import load_breast_cancer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.metrics import plot_roc_curve

X, y = load_breast_cancer(return_X_y=True)
pipe = make_pipeline(StandardScaler(), LogisticRegression())
pipe.fit(X, y)
plot_roc_curve(pipe, X, y)

推荐阅读