1

Can anyone help me make the top row of the confusion matrix not be cut in half. I am graphing a classification of 21 classes and my code is here:

def plot_confusion_matrix(y_true,y_predicted):
    cm = metrics.confusion_matrix(y_true, y_predicted)
    cm = list((cm.T / cm.astype(np.float).sum(axis=1)).T)
    
    #rounding the numbers to only 2 decimal places
    for y in range(0, 21):
        for x in range(0, 21):
            cm[x][y] = round(cm[x][y], 2)

    print ("Plotting the Confusion Matrix")
    labels = list(label_map.values())
    df_cm = pd.DataFrame(cm,index = labels,columns = labels)
    fig = plt.figure()
    res = sns.heatmap(df_cm, annot=True,cmap='Blues', fmt='g')
    
    plt.yticks([0.5,1.5,2.5,3.5,4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5], labels,va='center')
    
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
 
    plt.show()
    plt.close()

plot_confusion_matrix(y_test, rf_preds)

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • Welcome to StackOverflow ! I think you should remove the tag "machine-learning". While what you are working on may be related to that, your specific question does not appear to be so. – Patrick Jul 17 '20 at 02:22
  • 1
    Does this answer your question? [matplotlib/seaborn: first and last row cut in half of heatmap plot](https://stackoverflow.com/questions/56942670/matplotlib-seaborn-first-and-last-row-cut-in-half-of-heatmap-plot). Update matplotlib. – Trenton McKinney Jul 17 '20 at 04:12

0 Answers0