Skip to content
Advertisement

Plot confusion matrix with Keras data generator using sklearn

Sklearn clearly defines how to plot a confusion matrix using its own classification model with plot_confusion_matrix. But what about using it with Keras model using data generators? Let’s have a look at an example code:

First we need to train the model.

JavaScript

Now after the model is trained let’s build a confusion matrix.

JavaScript

Now this works fine so far. But how do I save it as png in the same layout as in the above sklearn example?

Advertisement

Answer

Like this (also see ConfusionMatrixDisplay and confusion_matrix):

JavaScript

Result:

confusion matrix plotted without scikit-learn's plot_confusion_matrix method

Advertisement