zero-to-mastery-ml
zero-to-mastery-ml copied to clipboard
Update Sklearn API `plot_roc_curve` -> `RocCurveDisplay`
Link to notebook changed: https://github.com/mrdbourke/zero-to-mastery-ml/blob/master/section-3-structured-data-projects/end-to-end-heart-disease-classification.ipynb
Error
As of Scikit-Learn 1.2+ the method sklearn.metrics.plot_roc_curve
is deprecated in favour of sklearn.metrics.RocCurveDisplay
.
How to check your Scikit-Learn version
You can check your Scikit-Learn version with:
import sklearn
sklearn.__version__
How to update your Scikit-Learn version
You can run the following command in your terminal with your Conda (or other) environment active to upgrade Scikit-Learn (the -U
stands for "upgrade):
pip install -U scikit-learn
Previous code (this will error if running Scikit-Learn version 1.2+)
# This will error if run in Scikit-Learn version 1.2+
from sklearn.metrics import plot_roc_curve
Also:
# This will error if run in Scikit-Learn version 1.2+
from sklearn.metrics import plot_roc_curve
plot_roc_curve(gs_log_reg, X_test, y_test);
New code (this will work with Scikit-Learn version 1.2+)
from sklearn.metrics import RocCurveDisplay # new in Scikit-Learn 1.2+
And to plot a ROC curve, note the use of RocCurveDisplay.from_estimator()
:
# Scikit-Learn 1.2.0 or later
from sklearn.metrics import RocCurveDisplay
# from_estimator() = use a model to plot ROC curve on data
RocCurveDisplay.from_estimator(estimator=gs_log_reg,
X=X_test,
y=y_test);
