how to find the labels of the confusion matrix in python

Solutions on MaxInterview for how to find the labels of the confusion matrix in python by the best coders in the world

showing results for - "how to find the labels of the confusion matrix in python"
Liliana
13 Apr 2018
1""" In order to find the labels just use the Counter function to count 
2the records from y_test and then check row-wise sum of the confusion 
3matrix. Then apply the labels to the corresponding rows using the 
4inbuilt seaborn plot as shown below"""
5
6from collections import Counter
7Counter(y_test).keys()
8Counter(y_test).values()
9
10import seaborn as sns
11import matplotlib.pyplot as plt     
12
13ax= plt.subplot()
14sns.heatmap(cm, annot=True, fmt='g', ax=ax);  #annot=True to annotate cells, ftm='g' to disable scientific notation
15
16# labels, title and ticks
17ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels'); 
18ax.set_title('Confusion Matrix'); 
19ax.xaxis.set_ticklabels(['business', 'health']); ax.yaxis.set_ticklabels(['health', 'business']);