plot_confusion_matrix() got an unexpected keyword argument 'classes' using sklearn

Viewed 6777

i am new to python and deep learning, i trained a multi classifier model and want to plot a confusion matrix but i am facing an error here is my code

from sklearn.metrics import plot_confusion_matrix
import matplotlib.pyplot as plt  
from sklearn.metrics import ConfusionMatrixDisplay
Y_pred = model.predict_generator(test_generator)
y_pred = np.argmax(Y_pred, axis=1)
category_names = sorted(os.listdir('D:/DiabaticRetinopathy/mq_dataset/DR_Normal/train'))
print(category_names)
cm = confusion_matrix(test_generator.classes, y_pred)
plot_confusion_matrix(cm, classes = category_names, title='Confusion Matrix', normalize=False, figname = 'Confusion_matrix_concrete.jpg')

i upddated my sklearn to 0.24 version. i restarted my kernel after updating but still its giving an error:

TypeError: plot_confusion_matrix() got an unexpected keyword argument 'classes'
3 Answers

There is a keyword labels, but not classes, so you can change it to that.

The error states that the keyword classes you provided is not a keyword that this function recognizes. This happens in your last line.

The documentation gives a list of the keywords that you can use: doc

Related