Skip to content

Bug: Confusion matrix misinterprets integer class labels as continuous rangeΒ #684

@guillaume-vignal

Description

@guillaume-vignal

Description

When using plot_confusion_matrix with integer class labels that are not contiguous (e.g., [1, 2, 10]), the function incorrectly interprets them as a continuous numeric range rather than as categorical labels.

As a result, the confusion matrix displays empty intermediate classes (e.g., 3–9), creating unwanted spacing in the visualization.

Integer labels should be treated as categorical values, not as numeric intervals.


πŸ“Œ Minimal Reproducible Example

from shapash.plots.plot_evaluation_metrics import plot_confusion_matrix

# Example lists of integer class labels
y_true_labels = [1, 2, 1, 10, 2, 1, 10, 2]
y_pred_labels = [1, 1, 1, 10, 2, 2, 10, 1]

plot_confusion_matrix(
    y_true=y_true_labels,
    y_pred=y_pred_labels,
    width=500,
    height=400
)

❗ Current Behavior

  • The confusion matrix assumes labels are continuous integers.
  • Intermediate class values (e.g., 3, 4, 5, 6, 7, 8, 9) are implicitly considered.
  • The resulting plot contains large empty gaps between actual labels (2 β†’ 10).
Image

βœ… Expected Behavior

  • Labels should be treated as categorical values.
  • Only observed unique labels should appear in the confusion matrix.
  • No artificial gaps between 2 and 10.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions