Python 混淆矩阵不支持多标签指标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46953967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multilabel-indicator is not supported for confusion matrix
提问by Khaine775
multilabel-indicator is not supported
is the error message I get, when trying to run:
multilabel-indicator is not supported
是我在尝试运行时收到的错误消息:
confusion_matrix(y_test, predictions)
confusion_matrix(y_test, predictions)
y_test
is a DataFrame
which is of shape:
y_test
是一个DataFrame
形状为:
Horse | Dog | Cat
1 0 0
0 1 0
0 1 0
... ... ...
predictions
is a numpy array
:
predictions
是一个numpy array
:
[[1, 0, 0],
[0, 1, 0],
[0, 1, 0]]
I've searched a bit for the error message, but haven't really found something I could apply. Any hints?
我已经搜索了一些错误消息,但还没有真正找到我可以应用的东西。任何提示?
回答by cs95
No, your input to confusion_matrix
must be a list of predictions, not OHEs (one hot encodings). Call argmax
on your y_test
and y_pred
, and you should get what you expect.
不,您的输入confusion_matrix
必须是预测列表,而不是 OHE(一种热编码)。调用argmax
你的y_test
and y_pred
,你应该得到你期望的结果。
confusion_matrix(
y_test.values.argmax(axis=1), predictions.argmax(axis=1))
array([[1, 0],
[0, 2]])
回答by Joshua Howard
The confusion matrix takes a vector of labels (not the one-hot encoding). You should run
混淆矩阵采用标签向量(不是单热编码)。你应该跑
confusion_matrix(y_test.values.argmax(axis=1), predictions.argmax(axis=1))