Scikit-learn 混淆矩阵根据字符串表现不同
Scikit-learn confusion matrix performing differently based on strings
我有一个非常奇怪的问题,我正在为我的数据集使用 sklearn 混淆矩阵 (from sklearn.metrics import confusion_matrix)
,但我注意到它打印的值相差甚远。我尝试调试它,它似乎适用于字母表的第一个字母,例如 "a"、"b"、"c"、"d" 和数字 (0, 1, 2, 3).
但是,如果我使用其他字母("g"、"r"、"m"、"o")或网站示例中的单词
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
我得到的结果非常随机。这是一个已知问题吗?我现在能想到的唯一解决方案是使用数字正确打印它,然后在 Paint 中修复标签。这不是我真正想要的论文解决方案。
据我所知这应该都是return第三个结果。有什么我遗漏的吗?或者有人遇到过这个问题吗?谢谢!
您将 classes
参数传递给 plot_confusion_matrix
与 confusion_matrix
所使用的参数不匹配,导致这些例程使用从 类 到混淆矩阵的行和列。 confusion_matrix
使用一种映射,plot_confusion_matrix
使用另一种,导致结果被打乱。
您需要 confusion_matrix
的 labels
参数匹配 plot_confusion_matrix
的 classes
参数:
confusion_matrix(gr, rr, labels=mr)
我有一个非常奇怪的问题,我正在为我的数据集使用 sklearn 混淆矩阵 (from sklearn.metrics import confusion_matrix)
,但我注意到它打印的值相差甚远。我尝试调试它,它似乎适用于字母表的第一个字母,例如 "a"、"b"、"c"、"d" 和数字 (0, 1, 2, 3).
但是,如果我使用其他字母("g"、"r"、"m"、"o")或网站示例中的单词
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
我得到的结果非常随机。这是一个已知问题吗?我现在能想到的唯一解决方案是使用数字正确打印它,然后在 Paint 中修复标签。这不是我真正想要的论文解决方案。
据我所知这应该都是return第三个结果。有什么我遗漏的吗?或者有人遇到过这个问题吗?谢谢!
您将 classes
参数传递给 plot_confusion_matrix
与 confusion_matrix
所使用的参数不匹配,导致这些例程使用从 类 到混淆矩阵的行和列。 confusion_matrix
使用一种映射,plot_confusion_matrix
使用另一种,导致结果被打乱。
您需要 confusion_matrix
的 labels
参数匹配 plot_confusion_matrix
的 classes
参数:
confusion_matrix(gr, rr, labels=mr)