Sometimes you encoded the labels to One Hot Version. Like when the labels are digits and you encoded them such as
1 -> [0,1,0,0,0,0,0,0,0,0]
We usually do this by:
from keras.utils import to_categoricaltrain_labels = to_categorical(train_labels)
In such cases, when calling confusion matrix on the output of the models and then trying to get the confusion matrix like:
from sklearn.metrics import confusion_matrix
you encounter an error like:
In order to fix such issue, you need to first decode which is calling
argmax on your “test_labels” and “predictions”, and you will get what you expect.
Why do we do this? Because the confusion matrix takes a vector of labels (not the one-hot encoding).
Here you will see how argmax works: