[Python] Python: Labels are only printing for half of my Confusion Matrix in Seaborn

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to visualize a confusion matrix for the output of a classification algorithm, but Seaborn is only printing the labels of the top half of my confusion matrix, as such:

    CM with missing labels

    As you can see, there are no labels in the positives row, even though the test (y_test) set does, in fact, have 240 positives in it.

    My code for generating the CM is as follows:

    cm = confusion_matrix(y_test, y_pred)

    plt.figure(figsize=(8, 6))
    sns.set_theme(style="whitegrid")
    sns.heatmap(cm, annot=True, fmt="d", cmap = "Blues")
    plt.title('Confusion Matrix - XGBoost with SMOTE')
    plt.xlabel('Predicted')
    plt.ylabel('Actual')
    plt.show()


    Any insight or help on why the labels are missing from the confusion matrix? Whatever thoughts you have would be much appreciated!

    Continue reading...

Compartilhe esta Página