Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH Add ClassificationReportDisplay to sklearn.metrics#34434

Open
cgivre wants to merge 4 commits into
scikit-learn:mainfrom
cgivre:classification-report-display-pr
Open

ENH Add ClassificationReportDisplay to sklearn.metrics#34434
cgivre wants to merge 4 commits into
scikit-learn:mainfrom
cgivre:classification-report-display-pr

Conversation

@cgivre

@cgivre cgivre commented Jul 5, 2026

Copy link
Copy Markdown

Reference Issues/PRs

See also #16880 (users wanting heatmap colors to reflect classification performance rather than sample counts).

What does this implement/fix? Explain your changes.

This adds metrics.ClassificationReportDisplay, a visual (heatmap) rendering of a classification report, analogous to the existing ConfusionMatrixDisplay. It covers the gap that third-party libraries such as Yellowbrick currently fill.

The display shows the per-class precision, recall and f1-score on a shared, fixed 01 color scale, so a cell's color reflects classification quality directly (unlike a raw confusion matrix, where color tracks the number
of samples). support is shown as a text-only column since it is a count, not a score. Rows are the individual classes followed by the macro avg and weighted avg summary rows; the scalar accuracy entry is intentionally left out of the grid.

Following the established Display conventions, three entry points are provided:

  • ClassificationReportDisplay(report) — visualize an existing report dict
    (the output of classification_report(..., output_dict=True));
  • ClassificationReportDisplay.from_predictions(y_true, y_pred, ...);
  • ClassificationReportDisplay.from_estimator(estimator, X, y, ...).

Metric computation is delegated entirely to classification_report; the display only handles layout. No new dependencies.

Included:

  • sklearn/metrics/_plot/classification_report.py — the display class;
  • tests in sklearn/metrics/_plot/tests/test_classification_report_display.py, including a check that the color scale is fixed to [0, 1] independent of support magnitude;
  • exports in sklearn/metrics/__init__.py, and entries in doc/api_reference.py and doc/visualizations.rst;
  • a changelog fragment;
  • a gallery example (examples/model_selection/plot_classification_report.py) and a paragraph in the Classification report section of the user guide.

First time contributor introduction

I'm a data scientist working in cyber security (and PMC chair for Apache Drill), and CEO at GTK Cyber. I use scikit-learn regularly and kept wanting a built-in visual companion to classification_report the same way ConfusionMatrixDisplay complements confusion_matrix, so I don't have to pull in an extra dependency for it. This is my attempt to contribute that upstream.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

Thank you for your consideration.

cgivre added 2 commits July 5, 2026 00:08
Adds a heatmap visualization of a classification report, analogous to
ConfusionMatrixDisplay. Renders per-class precision/recall/f1-score on a
shared 0-1 color scale with support as a text-only column, plus macro/
weighted average rows. Provides from_estimator, from_predictions, and a
constructor that visualizes an existing classification_report output_dict.
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@cgivre cgivre marked this pull request as ready for review July 7, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant