我使用以下函数生成混淆矩阵:def plot_confusion_matrix(cm, classes, normalize=False, cmap=cm.Blues, png_output=None, show=True):
"""
This function prints and plots the confusion matrix.
Normalization can be applied by setting `normalize=True`.
"""
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
title='Normalized confusion matrix'
else:
title='Confusion matrix'
f = plt.figure()
plt.imshow(cm, interpolation='nearest', cmap=cmap)
plt.title(title)
plt.colorbar()
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=45)
plt.yticks(tick_marks, classes)
fmt = '.2f' if normalize else 'd'
thresh = cm.max() / 2.
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
plt.text(j, i, format(cm[i, j], fmt),
horizontalalignment="center",
color="white" if cm[i, j] > thresh else "black")
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
if png_output is not None:
os.makedirs(png_output, exist_ok=True)
f.savefig(os.path.join(png_output,'confusion_matrix.png'), bbox_inches='tight')
if show:
plt.show()
plt.close(f)
else:
plt.close(f)
当我上几节课的时候,我会得到一张这样的图表:
但当我有大量的课程时,我会发现:
如何让我的混淆矩阵根据类的数量来调整它的大小,就像上面的boxplot解决方案一样?在
更新1
在包括了蜱虫的位置和动态飞行宽度之后
^{pr2}$
谨致问候。
克莱森·里奥斯。在