Skip to content
Advertisement

How to make a Confusion Matrix with Keras?

I have trained my model (multiclass classification) of CNN using keras and now I want to evaluate the model on my test set of images. Is there a way to create confusion matrix?

Advertisement

Answer

Thanks for answers. I did like this:

#Predict
y_prediction = model.predict(x_test)
y_prediction = np.argmax (y_prediction, axis = 1)
y_test=np.argmax(y_test, axis=1)
#Create confusion matrix and normalizes it over predicted (columns)
result = confusion_matrix(y_test, y_prediction , normalize='pred')
print(result)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement