我正在尝试运行下面的代码。
from sklearn.metrics import plot_confusion_matrix
我收到以下错误。
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-66-ebfa5cfc2bb8> in <module>
----> 1 from sklearn.metrics import plot_confusion_matrix
ImportError: cannot import name 'plot_confusion_matrix' from 'sklearn.metrics' (C:\Program Files\Anaconda3\lib\site-packages\sklearn\metrics\__init__.py)
plot_confusion_matrix
已弃用,因此请使用sklearn.metrics.ConfusionMatrixDisplay
画中画
pip install --upgrade scikit-learn
or
conda update -c conda-forge scikit-learn
从sklearn.metrics导入confusion_matrix
从 sklearn.metrics 导入 ConfusionMatrixDisplay
用这两个来代替
for cls in classifiers:
cls.fit(x_train,np.argmax(y_train,axis=1))
colors = [ 'YlOrBr', 'GnBu', 'Pastel2', 'PuRd']
for cls, ax, c in zip(classifiers, axes.flatten(), colors):
cm = confusion_matrix(np.argmax(y_test, axis=1), cls.predict(x_test))
disp = ConfusionMatrixDisplay(confusion_matrix=cm,
display_labels=names1)
disp.plot(ax=ax, cmap=c)
ax.title.set_text(type(cls).__name__)
plt.tight_layout()
plt.show()