python 混淆矩阵可视化

混淆矩阵:

import numpy as np
confusion = np.random.random([5,5]) + np.eye(5)*2
confusion = np.dot(np.linalg.inv(np.diag(np.sum(confusion,axis=1))),confusion)
print(confusion)

'''
[[0.50927103 0.07041116 0.04753256 0.16553774 0.20724751]
 [0.12732054 0.48133623 0.11226673 0.11855113 0.16052536]
 [0.15031137 0.13009076 0.51994749 0.19008082 0.00956956]
 [0.13469251 0.08813177 0.16790889 0.46202315 0.14724368]
 [0.19405227 0.04245825 0.10221693 0.14392883 0.51734372]]
'''

标签:

print(all_categories)
'''
['Arabic', 'Chinese', 'Czech', 'Dutch', 'English']
'''

可视化:

# Set up plot
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(confusion)
fig.colorbar(cax)

# Set up axes
ax.set_xticklabels([''] + all_categories, rotation=90)
ax.set_yticklabels([''] + all_categories)

# Force label at every tick
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))

# sphinx_gallery_thumbnail_number = 2
plt.show()

python 混淆矩阵可视化_第1张图片

你可能感兴趣的:(#,机器学习,#,编程语言)