EmotiW19比賽所用資料

繪製混淆矩陣

 

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# a=np.array([[0.65,0,0,0.12,0,0,0.18,0.03,0.02,0],[0,0.79,0.06,0.02,0.01,0,0,0,0,0.12],[0,0.03,0.74,0.16,0,0,0,0.01,0,0.06],[0.02,0.05,0,0.85,0,0,0.03,0.02,0,0.03],[0,0,0,0,0.94,0.03,0,0,0.03,0],[0,0,0,0.04,0.12,0.5,0,0.13,0.20,0.01],[0.08,0,0,0.01,0,0,0.84,0.07,0,0],[0.03,0,0,0.07,0,0.16,0.06,0.6,0.08,0],[0,0,0,0.02,0.01,0.02,0,0.06,0.89,0],[0,0.07,0.15,0.01,0.01,0,0.02,0.01,0,0.73]])
# cm = np.array([[77, 0, 3, 5, 8, 5, 0], [5, 0, 1, 11, 15, 8, 0], [17, 0, 33, 1, 12, 7, 0], [6, 0, 2, 126, 9, 1, 0],
#                [15, 0, 5, 15, 137, 21, 0], [11, 0, 6, 12, 16, 35, 0], [3, 0, 7, 3, 8, 7, 0]])

cm = np.array(
    [[69, 0, 5, 3, 14, 7, 0, ], [10, 1, 0, 9, 12, 8, 0], [13, 0, 33, 3, 12, 9, 0], [5, 0, 0, 130, 8, 1, 0],
     [25, 1, 7, 13, 131, 16, 0], [6, 0, 4, 9, 19, 42, 0], [3, 0, 8, 3, 8, 5, 1]])

cm_normalized = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
fig,ax=plt.subplots(figsize=(22,22))
sns.heatmap(cm_normalized,annot=True,vmax=1,square=True,cmap="Blues")
ticks=np.arange(0.5,7,1)
ax.xaxis.tick_top()
ax.set_xticks(ticks)
ax.set_yticks(ticks)
ax.set_xticklabels(['Angry', 'Disgust', 'Fear', 'Happy', 'Neutral', 'Sad', 'Surprise'],fontsize=15,rotation=45,horizontalalignment="left")
ax.set_yticklabels(['Surprise','Sad' ,'Neutral', 'Happy', 'Fear', 'Disgust', 'Angry'],fontsize=15,rotation=0)
plt.show()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章