【发布时间】:2020-04-06 17:27:06
【问题描述】:
我正在做一个 10 倍的验证,我需要看看每个类的准确性如何变化。我设法像这样创建了一个 DataFrame:
片段:
chars = []
for i in range(0, int(classes) + 1):
row = []
for j in range(0, int(classes) + 1):
row.append(str(round(means[i, j], 3)) + " +/- " + str(round(stds[i, j], 3)))
chars.append(row)
con_mat_df = pd.DataFrame(chars, index=classes_list, columns=classes_list)
0 1 ... 14 15
0 100.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
1 0.49 +/- 0.703 98.53 +/- 1.416 ... 0.0 +/- 0.0 0.0 +/- 0.0
2 0.0 +/- 0.0 0.12 +/- 0.36 ... 0.0 +/- 0.0 0.0 +/- 0.0
3 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
4 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
5 0.55 +/- 0.905 0.14 +/- 0.42 ... 0.0 +/- 0.0 0.0 +/- 0.0
6 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
7 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
8 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
9 0.62 +/- 1.318 0.2 +/- 0.6 ... 0.0 +/- 0.0 0.0 +/- 0.0
10 0.65 +/- 0.927 0.24 +/- 0.265 ... 0.0 +/- 0.0 0.0 +/- 0.0
11 1.02 +/- 1.558 0.0 +/- 0.0 ... 0.0 +/- 0.0 1.36 +/- 1.482
12 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
13 0.32 +/- 0.96 0.0 +/- 0.0 ... 0.0 +/- 0.0 0.0 +/- 0.0
14 0.78 +/- 1.191 0.0 +/- 0.0 ... 98.96 +/- 1.274 0.0 +/- 0.0
15 0.0 +/- 0.0 0.0 +/- 0.0 ... 0.0 +/- 0.0 94.78 +/- 6.884
[16 rows x 16 columns]
现在我只想像下面的例子那样绘制它。我想知道如何做到这一点。如果我使用sns.heatmap,它会抛出一个错误(TypeError: ufunc 'isnan' not supported for the input types...)。有任何想法吗?谢谢。
【问题讨论】:
-
Seaborn 热图需要绘制数字,但你有字符串。
-
我知道,这就是为什么我说我不能使用热图,因为它会引发错误。我故意创建了一个字符串数组(实际上是一个DataFrame),我想知道如何打印它,如图所示。
-
这根本不是它的工作原理。使用数字来绘制热图(使用
seaborn.heatmap或ax.imshow);然后根据自己的喜好放置文本标签;示例见matplotlib.org/3.1.1/gallery/images_contours_and_fields/… -
但我需要包括标准偏差,而不仅仅是数字。我多次使用热图来绘制一个只有浮点值的混淆矩阵。我不是说我想为此使用热图,我只是说“我怎样才能在我展示的图中绘制类似的东西”
-
我告诉你,你需要使用数字来绘制彩色像素。
标签: python pandas matplotlib heatmap confusion-matrix