python plot confusion matrix diagram

created at 06-29-2021 views: 7

1. Calculate the confusion matrix

# Import the package that calculates the confusion matrix
from sklearn.metrics import confusion_matrix

C1= confusion_matrix(True_label, T_predict1) 
  • True_label: true label, shape=(n,1);
  • T_predict1: predicted label, shape=(n,1)


2. Use seaborn's thermal diagram plot confusion matrix

import seaborn as sns 


sns.heatmap(C1,fmt='g', cmap='blue',annot=True,cbar=False,xticklabels=xtick, yticklabels=ytick)
  • annot=True means display the corresponding value on the graph,
  • fmt attribute means the format of the output value,
  • cbar=False: do not display the heat bar

Please log in to leave a comment.