Reputation: 2440
I am trying to plot a Receiver Operating Characteristics (ROC) curve with cross validation, following the example provided in sklearn's documentation. However, the following import gives an ImportError
, in both python2
and python3
.
from sklearn.metrics import plot_roc_curve
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name plot_roc_curve
python-2.7
sklearn version: 0.20.2.
python-3.6
sklearn version: 0.21.3.
I found that the following import works fine, but it's not quite the same as plot_roc_curve
.
from sklearn.metrics import roc_curve
Is plot_roc_curve
deprecated? Could somebody try the code and let me know the sklearn version if it works?
Upvotes: 12
Views: 42311
Reputation: 21
Use RocCurveDisplay
instead of plot_roc_curve
:
from sklearn.metrics import RocCurveDisplay
then you can use it as such:
RocCurveDisplay.from_estimator(clf, X_test, y_test)
Upvotes: 0
Reputation: 11
plot_roc_curve
was deprecated and removed from sklearn
in version 1.2.
Use RocCurveDisplay
: Instead of plot_roc_curve
, the current method to plot ROC curves is through the RocCurveDisplay
class in sklearn.metrics
.
So try:
from sklearn.metrics import RocCurveDisplay
Upvotes: 0
Reputation: 1
for
ImportError: cannot import name 'plot_roc_curve' from 'sklearn.metrics'
use RocCurveDisplay
instead of plot_roc_curve
as in from sklearn.metrics import RocCurveDisplay
Upvotes: 0
Reputation: 11
As the official sklearn's document mentioned: The function plot_roc_curve
is deprecated in 1.0 and will be removed in 1.2. If you would like more detail, please refer to here.
Use one of the class methods: sklearn.metric.RocCurveDisplay.from_predictions
or sklearn.metric.RocCurveDisplay.from_estimator
. f you would like more detail, please refer to here.
Upvotes: 1
Reputation: 301
plot_roc_curve has been removed in version 1.2. From 1.2, use RocCurveDisplay instead:
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_)
Upvotes: 20
Reputation: 61
I updated Conda
with conda update --all
and then updated scikit-learn
to the latest version which for me was conda install scikit-learn=0.23.2
and restarted the kernel. After that my errors were gone.
Upvotes: 1
Reputation: 99
Install scikit-plot and import the metric from there:
from scikitplot.metrics import plot_roc_curve
Upvotes: 9
Reputation: 5696
Plotting API was introduced in the version 0.22. As mentioned here, Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4. Scikit-learn now requires Python 3.5 or newer.
Upvotes: 5