[Solved] Confusion matrix fails to show all labels


I think there is confusion here! a confusion matrix is set(y_test) + set(y_pred). so if this comes to be 8. then the matrix will be 8 X 8. Now, if you have more labels you want to print even though it does not matter if it’s all zero. then while building the matrix , you need to feed “labels” parameter.

y_true = [2, 0, 2, 2, 0, 1,5]
y_pred = [0, 0, 2, 2, 0, 2,4]
confusion_matrix = confusion_matrix(y_true, y_pred,labels=[0,1,2,3,4,5,6])

as you can see, 6 is really not there in y_true or y_pred, you will zeros for it.
enter image description here

1

solved Confusion matrix fails to show all labels