简体   繁体   English

更改混淆矩阵(sklearn)中的值

[英]Changing values in confusion_matrix (sklearn)

How can i change a numbers values to letters in both axis?如何在两个轴上将数字值更改为字母? I got dictionary with keys = letters and values = numbers我得到了带有键=字母和值=数字的字典

Code:代码:

cm = confusion_matrix(y_class, y_pred_class)
disp = ConfusionMatrixDisplay(confusion_matrix=cm)
fig, ax = plt.subplots(figsize=(10,10))
ax.set_title("Confusion Matrix for Artificial neural network")
disp.plot(ax=ax)
plt.show()

confusion_matrix混淆矩阵

Dict:字典:

{
 'A': 7,'B': 6,'C': 14,'D': 2,'E': 19,'F': 13,
 'G': 4,'H': 15, 'I': 1, 'J': 8, 'K': 24, 'L': 17,
 'M': 9, 'N': 3, 'O': 11, 'P': 18 'Q': 22, 'R': 12,
 'S': 5, 'T': 0, 'U': 23, 'V': 20, 'W': 16, 'X': 10,
 'Y': 21, 'Z': 25
}

You can do this by setting the x and y axis labels with .set_ticklabels() :您可以通过使用.set_ticklabels()设置 x 和 y 轴标签来做到这一点:

ax.xaxis.set_ticklabels([...])
ax.yaxis.set_ticklabels([...])

Where the list just contains the values you want.列表只包含您想要的值。 This will replace the default numbers of the matrix plot.这将替换矩阵图的默认数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM