Tensorflow 在使用tensorboard查看混淆矩阵时,如何绘制混淆矩阵的实际数字以及颜色?

Tensorflow 在使用tensorboard查看混淆矩阵时,如何绘制混淆矩阵的实际数字以及颜色?,tensorflow,matplotlib,tensorboardx,Tensorflow,Matplotlib,Tensorboardx,我正在运行此Github上提供的代码- 现在我可以看到颜色变化的混淆矩阵,但我看不到实际的数字。您建议进行哪些更改以在可视化上显示这些数字?您可以将混淆矩阵\u更改为\u fig更改为: import itertools def confusion_matrix_to_fig(self): cm = self.confusion_matrix.astype('float') / (self.confusion_matrix.sum(axis=1) +

我正在运行此Github上提供的代码-


现在我可以看到颜色变化的混淆矩阵,但我看不到实际的数字。您建议进行哪些更改以在可视化上显示这些数字?

您可以将
混淆矩阵\u更改为\u fig
更改为:

import itertools

def confusion_matrix_to_fig(self):
    cm = self.confusion_matrix.astype('float') / (self.confusion_matrix.sum(axis=1) +
                                                  0.000001)[:, np.newaxis]
    fig, ax = plt.subplots()
    im = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
    ax.figure.colorbar(im, ax=ax)

    ax.set(title=f'Confusion Matrix', ylabel='True label', xlabel='Predicted label')

    # Adding text to cm
    thresh = cm.max() / 1.5  # Thresh is used to decide color of text (white or black)
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        ax.text(j, i, "{:0.4f}".format(cm[i, j]),
                  horizontalalignment="center",
                  color="white" if cm[i, j] > thresh else "black")

    fig.tight_layout()
    return fig
正如您可能已经注意到的,这将绘制混淆矩阵的规范化值


查看更多信息。

到回购的链接不足。始终提供完整的代码、数据、错误、当前输出和预期输出,如图所示。如果相关,则仅打印图像即可。请看。谢谢你的帮助,我会记住的。这很有效,非常感谢。@RamMohan很高兴我能帮上忙。请随意接受它作为答案,也可以帮助其他开发人员。