The normalized confusion matrix

A normalized confusion matrix makes it easier for the data scientist to visually interpret how the labels are being predicted. In order to construct a normalized confusion matrix, we use the following code:

import matplotlib.pyplot as pltimport scikitplot as skplt#Normalized confusion matrix for the K-NN modelprediction_labels = knn_classifier.predict(X_test)skplt.metrics.plot_confusion_matrix(y_test, prediction_labels, normalize=True)plt.show()

This results in the following normalized confusion matrix:

Normalized confusion matrix for the K-NN model

In the preceding plot, the predicted labels are along the ...

Get Machine Learning with scikit-learn Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.