Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sklearn won't properly import plot_confusion_matrix

I am currently trying to follow this scikit-learn example to plot a confusion matrix for a classifier I have. However, I get an import error whenever I try and import with this line from my terminal:

 >>> from sklearn.metrics import plot_confusion_matrix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'plot_confusion_matrix' from 'sklearn.metrics' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/metrics/__init__.py)

The main goal is to get this to work on a jupyter notebook (currently being run on Google Colab). The same import line gets this error:

ImportError: cannot import name 'plot_confusion_matrix'

Note that I have re-updated my sklearn, scipy, and numpy on my terminal and gotten the same error. Here is the documentation for plot_confusion_matrix.

like image 549
mckennab Avatar asked Dec 04 '19 05:12

mckennab


1 Answers

The answer: I was updating my sklearn instead of scikit-learn. This module is only available starting at 0.22, and I was running 0.21.2. Thanks @VivekKumar!

like image 192
mckennab Avatar answered Oct 15 '22 09:10

mckennab