I had a classification problem in which I trained a CNN and now I was hoping I could obtain its confusion matrix. I tried the following:
from sklearn.metrics import confusion_matrix
y_pred = model.predict(x_test)
#Generate the confusion matrix
cf_matrix = confusion_matrix(y_test, y_pred)
print(cf_matrix)
But I got the following error:
ValueError: Classification metrics can't handle a mix of unknown and continuous-multioutput targets
x_test
is made of (84, 32, 32)
- 84 monochrome images of shape 32x32
Is there a way around this problem?
Addendum: Model Summary (note: the output activation fn is softmax)
CodePudding user response:
Just to sum it up from the comments, there were two problems:
confusion_matrix
expects the class labels and not the logits output from the Dense layer with softmax activation. This is fixed simply by doing:
y_pred = np.argmax(y_pred, axis=1)
y_true
is identified as having targets ofunknown
type (see the error). Hence, make sure it has the correct type of data (i.e., the true class labels).