sklearn plot confusion matrix with labels

前端 未结 7 1228
生来不讨喜
生来不讨喜 2020-11-29 19:09

I want to plot a confusion matrix to visualize the classifer\'s performance, but it shows only the numbers of the labels, not the labels themselves:

from skl         


        
7条回答
  •  猫巷女王i
    2020-11-29 19:26

    UPDATE:

    In scikit-learn 0.22, there's a new feature to plot the confusion matrix directly.

    See the documentation: sklearn.metrics.plot_confusion_matrix


    OLD ANSWER:

    I think it's worth mentioning the use of seaborn.heatmap here.

    import seaborn as sns
    import matplotlib.pyplot as plt     
    
    ax= plt.subplot()
    sns.heatmap(cm, annot=True, ax = ax); #annot=True to annotate cells
    
    # labels, title and ticks
    ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels'); 
    ax.set_title('Confusion Matrix'); 
    ax.xaxis.set_ticklabels(['business', 'health']); ax.yaxis.set_ticklabels(['health', 'business']);
    

提交回复
热议问题