其他分享
首页 > 其他分享> > plot confusion_matrix

plot confusion_matrix

作者:互联网

import seaborn as sns
sns.set(font_scale=1.4) # y label 横向
import matplotlib.pyplot as plt

'''
https://zhuanlan.zhihu.com/p/35494575
fmt ='.0%'#显示百分比
fmt ='f' 显示完整数字 = fmt ='g'
fmt ='.3'显示小数的位数 = fmt ='.3f' = fmt ='.3g'
'''

confusion_matrix = pd.DataFrame(data = np.array([[99.9,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0],
                             [0.0,  99.9,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0],
                             [0.0,  0.0,  99.9,  0.0,  0.0,  0.0,  0.0,  0.0],
                             [0.0,  0.0,  0.0,  99.9,  0.0,  0.0,  0.0,  0.0],
                             [0.0,  0.0,  0.0,  0.0,  99.9,  0.0,  0.0,  0.0],
                             [0.0,  0.0,  0.0,  0.0,  0.0,  99.9,  0.0,  0.0],
                             [0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  99.9,  0.0],
                             [0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0, 99.9]]),
                             index = list(range(8)),columns = list(range(8)))

f, ax = plt.subplots(figsize=(8,6))
df_cm = pd.DataFrame(confusion_matrix)
sns.heatmap(df_cm,annot=True,vmax=100.0,vmin = 0.0,fmt ='.1f',cmap = 'Greys',annot_kws={'size': 14})

label_x = ax.get_xticklabels()
label_y = ax.get_yticklabels()
plt.setp(label_x, rotation=45, horizontalalignment='right',fontsize=16)
plt.setp(label_y,  fontsize=16)

plt.xlabel('Predicted Emotion',fontsize=20)
plt.ylabel('True Emotion',fontsize=20)

plt.savefig('./fig_confusion_matrix_of_label_embedding_prediction.png')

plt.show()

在这里插入图片描述在这里插入图片描述

标签:plot,plt,matrix,0.0,fmt,label,99.9,confusion
来源: https://blog.csdn.net/weixin_48354103/article/details/110355169