ENH Add ClassificationReportDisplay to sklearn.metrics#34434
Open
cgivre wants to merge 4 commits into
Open
Conversation
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.
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingConfusionMatrixDisplay. It covers the gap that third-party libraries such as Yellowbrick currently fill.The display shows the per-class
precision,recallandf1-scoreon a shared, fixed0–1color scale, so a cell's color reflects classification quality directly (unlike a raw confusion matrix, where color tracks the numberof samples).
supportis shown as a text-only column since it is a count, not a score. Rows are the individual classes followed by themacro avgandweighted avgsummary rows; the scalaraccuracyentry is intentionally left out of the grid.Following the established
Displayconventions, 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;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;sklearn/metrics/__init__.py, and entries indoc/api_reference.pyanddoc/visualizations.rst;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_reportthe same wayConfusionMatrixDisplaycomplementsconfusion_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:
Any other comments?
Thank you for your consideration.