【发布时间】:2021-02-24 05:27:03
【问题描述】:
背景
在混淆矩阵中,对角线表示预测标签与正确标签匹配的情况。所以对角线是好的,而所有其他的单元格都是坏的。为了澄清非专家在 CM 中什么是好的和什么是坏的,我想给对角线一个与其他颜色不同的颜色。我想通过 Python 和 Seaborn 实现这一目标。
基本上我正在尝试实现这个问题在 R 中的作用 (ggplot2 Heatmap 2 Different Color Schemes - Confusion Matrix: Matches in Different Color Scheme than Missclassifications)
带有热图的普通 Seaborn 混淆矩阵
import numpy as np
import seaborn as sns
cf_matrix = np.array([[50, 2, 38],
[7, 43, 32],
[9, 4, 76]])
sns.heatmap(cf_matrix, annot=True, cmap='Blues') # cmap='OrRd'
这会导致此图像:
目标
我想用例如颜色为非对角单元格着色cmap='OrRd'。所以我想会有 2 个颜色条,1 个蓝色用于对角线,1 个用于其他单元格。最好两个颜色条的值都匹配(例如,0-70 而不是 0-70 和 0-40)。
我该如何处理?
以下不是用代码做的,而是用照片编辑软件做的:
【问题讨论】:
标签: python matplotlib seaborn heatmap confusion-matrix