Skip to content
Advertisement

How to Calculate Confusion Matrix on test Data?

I want to plot a confusion matrix on the validation data.

Specifically, I want to calculate a confusion matrix of the model output on the validation data.

I tried everything online, but couldn’t figure it out.

here is my model:

JavaScript

Advertisement

Answer

Here is a dummy example.

DataSet

JavaScript

Model

JavaScript

Confusion Matrix

Your interest is mostly here.

JavaScript

Visualization

Let’s visualize.

JavaScript

enter image description here

Update

Based on the conversation, if you’ve to use

JavaScript

then don’t transform your integer label as I’ve shown you above (i.e. y_train = tf.keras.utils.to_categorical(y_train, num_classes=10)). But do just as follows

JavaScript

And in predicting time don’t use np.argmax() on ground truth as they are already an integer now as we didn’t use tf.keras.utils.to_categorical this time.

JavaScript

Now rest of the stuff is good to use.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement