ValueError: Classification metrics can't handle a mix of multilabel-indicator and binary targets

hello everybody!

I was trying to to an multiclass classification with a cnn, but when I try to

from sklearn.metrics import accuracy_score

accuracy_score(y_test_, prediction.round(),normalize=True)

this error accoured:

ValueError: Classification metrics can’t handle a mix of multilabel-indicator and binary targets

Could anyone help me?
I’ll write all the code you need to explain me better.
Really thanks

Could you post the shapes od y_test and prediction?
Based on the error message, I assume accuracy_score expects other shapes than the one you’ve passed.

shapes are

y_test_ (12630,43)
I am sure that you are right. How can I fix it?
Really thanks

Based on the docs 1-dimensional tensors are required by this method.
If your target is one-hot encoded, you could get the class indices via y_test = torch.argmax(y_test, dim=1).

Really thanks for the support, I found the mistake.
You helped me to reason on my code.

1 Like