How to add class labels to confusion matrix of multi class classification

How do I add class labels to the confusion matrix? The label display number in the label not the actual value of the label Eg. labels = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

Here is the code I used to generate it.

x_train, y_train, x_test, y_test = train_images, train_labels, test_images, test_labels
model = KNeighborsClassifier(n_neighbors=7, metric='euclidean')
model.fit(x_train, y_train)
# predict labels for test data
predictions = model.predict(x_test)

# Print overall accuracy
print(KNN Accuracy = , metrics.accuracy_score(y_test, predictions))

# Print confusion matrix
cm = confusion_matrix(y_test, predictions)

plt.subplots(figsize=(30, 30))         # Sample figsize in inches
sns.set(font_scale=2)
sns.heatmap(cm, annot=True)

Topic multiclass-classification accuracy confusion-matrix python

Category Data Science


You can use the xticklabels and yticklabels arguments for this as specified in the seaborn documentation. See also the following answer on a different question on the datascience stackexchange.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.