Search code examples
pythonmachine-learningscikit-learnroc

sklearn ImportError: cannot import name plot_roc_curve


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?


Solution

  • 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.