混淆矩阵不支持多标签指示器

2024-04-24 20:44:45 发布

您现在位置:Python中文网/ 问答频道 /正文

multilabel-indicator is not supported是我在尝试运行时收到的错误消息:

confusion_matrix(y_test, predictions)

y_test是一个DataFrame形状:

Horse | Dog | Cat
1       0     0
0       1     0
0       1     0
...     ...   ...

predictions是一个numpy array

[[1, 0, 0],
 [0, 1, 0],
 [0, 1, 0]]

我已经搜索了一点错误信息,但还没有找到可以应用的东西。有什么线索吗?


Tags: test消息dataframeis错误notmatrixindicator
2条回答

混淆矩阵接受一个标签向量(而不是一个热编码)。你应该逃跑

confusion_matrix(y_test.values.argmax(axis=1), predictions.argmax(axis=1))

不,您对^{}的输入必须是预测列表,而不是OHEs(一个热编码)。在你的y_testy_pred上调用argmax,你应该得到你期望的结果。

confusion_matrix(
    y_test.values.argmax(axis=1), predictions.argmax(axis=1))

array([[1, 0],
       [0, 2]])

相关问题 更多 >