def plot_confusion_matrix(cm, target_names, title='Confusion matrix', cmap=plt.cm.Greys, block=True):
# Colormaps: jet, Greys
cm_normalized = cm.astype(np.float32) / cm.sum(axis=1)[:, np.newaxis]
plt.imshow(cm_normalized, interpolation='nearest', cmap=cmap)
# Show confidences
for i, cas in enumerate(cm):
for j, c in enumerate(cas):
if c > 0:
plt.text(j-0.1, i+0.2, c, fontsize=16, fontweight='bold', color='#b70000')
f = plt.figure(1)
f.clf()
plt.title(title)
plt.colorbar()
tick_marks = np.arange(len(target_names))
plt.xticks(tick_marks, target_names, rotation=45)
plt.yticks(tick_marks, target_names)
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show(block=block)
评论列表
文章目录