你能改变混淆矩阵的轮廓颜色吗?

时间:2021-01-08 16:48:24

标签: python scikit-learn seaborn confusion-matrix

这可能是一个可以回答的简单问题,但是否可以更改混淆矩阵的轮廓颜色?

使用代码生成混淆矩阵,没有轮廓:

cm = metrics.confusion_matrix(y, predictions)
fig, ax = plt.subplots(figsize=(12,12))
sns.heatmap(cm, ax=ax, cbar=False, annot=True, fmt='d', cmap='gist_yarg', linewidths=0.1)
ax.set_xticklabels(['a','b']);
ax.set_yticklabels(['a','b']);
ax.set_xlabel('my_label')
ax.set_ylabel('my_label')

我的混淆矩阵生成,但它没有轮廓 - 所以可以将轮廓更改为纯色,如黑色?

谢谢!

1 个答案:

答案 0 :(得分:0)

默认情况下,线条颜色为白色,因此您在使用 gist_yarg 颜色方案时看不到它,您可以使用 linecolor= 进行设置:

from sklearn import metrics
import seaborn as sns

y = np.random.choice([0,1],50)
predictions = np.random.choice([0,1],50)

cm = metrics.confusion_matrix(y, predictions)
fig, ax = plt.subplots(figsize=(5,5))
sns.heatmap(cm, ax=ax, cbar=False, annot=True, fmt='d', cmap='gist_yarg', 
linewidths=0.1,linecolor='lightblue')

enter image description here

相关问题