0

A question about the layout of my confusion matrix. I would like to replace the numbers "0", "1" and "2" corresponding to the variable labels with the actual variable labels which are "Bare soil", "Corn" and "Other crop". Thank for your help.

CM = confusion_matrix(y_test, y_pred)
CM = sns.heatmap(CM, square = True, cmap = "coolwarm", linewidths = .5, annot = True)
plt.title('Model confusion matrix', fontsize = 20) 
plt.xlabel('Predict', fontsize = 15) 
plt.ylabel('Real', fontsize = 15) 
plt.show()

Confusion matrix

flaxel
  • 4,173
  • 4
  • 17
  • 30
Carl Bethuel
  • 37
  • 10
  • 1
    You can use [Panda](https://stackoverflow.com/a/50326049/10951752) for it or you can use also the [plot_confusion_matrix](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.plot_confusion_matrix.html). – flaxel Oct 01 '20 at 13:16

1 Answers1

0

Try plt.yticks, plt.xticks:

import matplotlib.pyplot as plt
sns.heatmap(confusion_matrix(y_test,y_pred),annot=True)
plt.yticks(np.arange(3)+0.5,('X1','X2','X3'), fontsize="10")
plt.xticks(np.arange(3)+0.5,('X1','X2','X3'), fontsize="10" )

Source

Vaziri-Mahmoud
  • 152
  • 1
  • 10