티스토리 뷰


from sklearn.metrics import plot_roc_curve
plot_roc_curve(clf, x_test, y_test)

실행하면 다음과 같은 에러가 난다.
ImportError: cannot import name 'plot_roc_curve' from 'sklearn.metrics' (/usr/local/lib/python3.10/dist-packages/sklearn/metrics/__init__.py)

구글링 해보면 sklearn 버전 1.2부터 plot_roc_curve가 RocCurveDisplay로 바뀌었단다.
호출방식도 바뀌었음

---------------------------
Before sklearn 1.2:
---------------------------
from sklearn.metrics import plot_roc_curve
svc_disp = plot_roc_curve(svc, X_test, y_test)
rfc_disp = plot_roc_curve(rfc, X_test, y_test, ax=svc_disp.ax_)

---------------------------
From sklearn 1.2:
---------------------------
from sklearn.metrics import RocCurveDisplay
svc_disp = RocCurveDisplay.from_estimator(svc, X_test, y_test)
rfc_disp = RocCurveDisplay.from_estimator(rfc, X_test, y_test, ax=svc_disp.ax_)

(src : https://stackoverflow.com/questions/60321389/sklearn-importerror-cannot-import-name-plot-roc-curve)


댓글