如何在没有额外列的情况下实现 scikit-learn 混淆矩阵?

问题描述 投票:0回答:1

我有一个可以进行二元分类的分类器。对于训练,我使用我信任的数据。 为了进行测试,我使用了我信任的数据以及一些不太好的数据(真实世界数据)。

如何在没有额外列的情况下获得混淆矩阵?

这是我的测试代码

import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

y_test = [0, 1, 1, 1, 2, 2, 3]
predictions = [0, 1, 1, 1, 0, 1, 0]

cm = confusion_matrix(y_test, predictions)

l = ["M", "F", "M?", "F?"]
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=l)
disp.plot()
plt.show()

See? Unnecessary columns are here

我错过了什么吗?

请随意说我完全错了。

python matplotlib scikit-learn classification confusion-matrix
1个回答
0
投票

它为您提供 4 列,因为在 y_test 中您没有二进制信息(不仅是 0 或 1)。

所以基本上你的基本事实似乎是多类分类的基本事实(从0到3的整数)。

例如,如果您将 y_pred 中的 2 和 3 替换为 0 或 1,您将得到一个您想要的 2x2 矩阵。

© www.soinside.com 2019 - 2024. All rights reserved.