我想用 min=0
和 max=15075
(共享here)绘制 66x66
混淆矩阵 . 因为我想注释细胞,我使用的是 annot=True
. 但即使尝试了其他堆栈溢出帖子(如this,this和this)中建议的方法,我似乎也无法适应单元格中的值 . 这是我目前的代码:
from sklearn.metrics import confusion_matrix
conf_mat = confusion_matrix(y_test, y_pred) # please load the data from the pastebin [link above][1]
# get the tick label font size
fontsize_pt = 10 # plt.rcParams['ytick.labelsize'] does not return a numeric value like suggested [here][2], so I set it to '10'
dpi = 72.27
# comput the matrix height in points and inches
matrix_height_pt = fontsize_pt * conf_mat.shape[0]
matrix_height_in = matrix_height_pt / dpi
# compute the required figure height
top_margin = 0.04
bottom_margin = 0.04
figure_height = matrix_height_in / (1 - top_margin - bottom_margin)
# build the figure instance with the desired height
fig, ax = plt.subplots(figsize=(20, figure_height),
gridspec_kw=dict(top=(1-top_margin), bottom=bottom_margin))
# here, I turned on annot and changed the color map scheme
ax = sns.heatmap(conf_mat, ax=ax, annot=True, cmap="cubehelix")
当我运行上面的代码时,它返回一个看起来像这样的数字
我希望带注释的数字适合热图的每个单元格,如果可能的话,颜色范围要更合理一些(而不是像现在这样全部是黑色) .
任何改进的建议将不胜感激 . 谢谢 .