gpt4 book ai didi

python - 热图中转置混淆矩阵的原因

转载 作者:行者123 更新时间:2023-12-01 02:46:40 24 4
gpt4 key购买 nike

我绘制了一个热图,它将混淆矩阵作为输入数据。混淆矩阵的形状为:

 [[37  0  0  0  0  0  0  0  0  0]
[ 0 42 0 0 0 1 0 0 0 0]
[ 1 0 43 0 0 0 0 0 0 0]
[ 0 0 0 44 0 0 0 0 1 0]
[ 0 0 0 0 37 0 0 1 0 0]
[ 0 0 0 0 0 47 0 0 0 1]
[ 0 0 0 0 0 0 52 0 0 0]
[ 0 0 0 0 1 0 0 47 0 0]
[ 0 1 0 1 0 0 0 1 45 0]
[ 0 0 0 0 0 2 0 0 0 45]]

绘制热图的代码是:

fig2=plt.figure()
fig2.add_subplot(111)
sns.heatmap(confm.T,annot=True,square=True,cbar=False,fmt="d")
plt.xlabel("true label")
plt.ylabel("predicted label")

产生:

enter image description here

如您所见,输入矩阵“confm”已转置 (confm.T)。这是什么原因呢?我必须这样做吗?

最佳答案

当我使用您提供的代码绘制数据时,我得到以下信息: enter image description here

在没有转置的情况下,当交换 x 和 y 标签时,您会得到:

fig2=plt.figure()
fig2.add_subplot(111)
sns.heatmap(confm,annot=True,square=True,cbar=False,fmt="d")
plt.xlabel("predicted label")
plt.ylabel("true label")

enter image description here

这会产生相同的混淆矩阵。转置真正做的是交换哪个是预测,哪个是基本事实(真实标签)。您需要使用什么取决于数据的格式。

关于python - 热图中转置混淆矩阵的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45192483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com