每个细胞具有不同色标的seaborn的混淆矩阵
我想用True/False Positive/Negative
创建混淆矩阵图。
目标是使数字在 [0.0, 1.0]
范围内,对于 True Negative/Positive
,色标为 red->green< /code>,
假阴性/阳性
则为绿色->红色
。我在seaborn文档中没有找到任何可以这样做的内容,这可能吗?它可以快速浏览数据,任何红色的东西都会有问题。
目标是左上和右下单元格具有与左下和右上不同的颜色图。这可能吗?
示例代码:
import numpy as np;
import seaborn as sns;
sns.set_theme()
uniform_data = np.ndarray(shape=(2,2))
uniform_data[0][0] = 0.1
uniform_data[0][1] = 0.9
uniform_data[1][0] = 0.05
uniform_data[1][1] = 0.95
ax = sns.heatmap(uniform_data, annot=True, cmap=sns.color_palette("vlag", as_cmap=True))
图像中的结果:
但我想要的是左上角为红色(因为 0.1 在这里是一个不好的值),右下角为蓝色(因为这里 0.95 是好的值)
I want to create a plot of a confusion matrix with True/False Positive/Negative
.
The goal is to have the numbers in the range [0.0, 1.0]
, and for True Negative/Positive
, the color scale be red->green
, and for the False Negative/Positive
for it to be green->red
. I have not found anything in the seaborn documentation to do so, is it even possible? It would allow a quick glance over the data, and anything red would be a problem.
The goal would be left top and bottom right cells have a different color map than left bottom and right top. Is this possible?
Example code:
import numpy as np;
import seaborn as sns;
sns.set_theme()
uniform_data = np.ndarray(shape=(2,2))
uniform_data[0][0] = 0.1
uniform_data[0][1] = 0.9
uniform_data[1][0] = 0.05
uniform_data[1][1] = 0.95
ax = sns.heatmap(uniform_data, annot=True, cmap=sns.color_palette("vlag", as_cmap=True))
results in the image:
But what I would want is to be top left red (as 0.1 is a bad value here), and bottom right blue (as 0.95 is good here)
So something like this (done quickly with paint, so don't mind the errors, but the sentiment is there):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您想反转对角线上元素的颜色。
sns.heatmap
的data
参数决定颜色,而annot=
参数可以为注释设置不同的内容。修改数据并保留注释的原始内容:It seems you want to invert the colors of the elements on the diagonal. The
data
argument ofsns.heatmap
decides on the colors, while theannot=
argument can set something different for the annotation. Modifying the data and keeping the original for the annotation: