mrdbourke / zero-to-mastery-ml

All course materials for the Zero to Mastery Machine Learning and Data Science course.
https://dbourke.link/ZTMmlcourse
2.88k stars 3.4k forks source link

Update Sklearn API `plot_roc_curve` -> `RocCurveDisplay` #45

Open mrdbourke opened 1 year ago

mrdbourke commented 1 year ago

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); 
Screenshot 2023-02-23 at 4 31 34 pm
Dhrubaraj-Roy commented 7 months ago

Thank you!!!

kRiShNa-429407 commented 7 months ago

Thank you