Multilabel-indicator is not supported for confusio

2019-01-15 13:35发布

multilabel-indicator is not supported is the error message I get, when trying to run:

confusion_matrix(y_test, predictions)

y_test is a DataFrame which is of shape:

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

predictions is a 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?

2条回答
成全新的幸福
2楼-- · 2019-01-15 14:04

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(
    y_test.values.argmax(axis=1), predictions.argmax(axis=1))

array([[1, 0],
       [0, 2]])
查看更多
Emotional °昔
3楼-- · 2019-01-15 14:22

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))
查看更多
登录 后发表回答