Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:DistrictDataLabs Yellowbrick ClassificationReport Visualizer

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, Classification, Visualization
Last Updated 2026-02-08 00:00 GMT

Overview

Concrete tool for rendering per-class precision, recall, F1, and support scores as a color-coded heatmap, provided by the Yellowbrick library.

Description

The ClassificationReport class is a classification score visualizer that generates the scikit-learn precision_recall_fscore_support metrics and renders them as a heatmap. Each row represents a class and each column represents a metric (precision, recall, F1, and optionally support). The heatmap uses a configurable colormap (defaulting to "YlOrRd") with 100% accurate cells highlighted in green. The support column can be displayed as raw counts, percentages, or omitted entirely.

The companion quick method classification_report() provides a one-call interface that instantiates the visualizer, fits the classifier, scores it, and renders the plot.

Usage

Use ClassificationReport when evaluating a trained classifier and you want a visual per-class breakdown of precision, recall, and F1 scores. It is especially valuable for multiclass problems where a text-based report is hard to scan quickly.

Code Reference

Source Location

  • Repository: yellowbrick
  • File: yellowbrick/classifier/classification_report.py
  • Class Lines: L131-216 (ClassificationReport class)
  • Quick Method Lines: L325-464 (classification_report function)

Signature

class ClassificationReport(ClassificationScoreVisualizer):
    def __init__(
        self,
        estimator,
        ax=None,
        classes=None,
        cmap="YlOrRd",
        support=None,
        encoder=None,
        is_fitted="auto",
        force_model=False,
        colorbar=True,
        fontsize=None,
        **kwargs
    )

    def score(self, X, y)
def classification_report(
    estimator,
    X_train,
    y_train,
    X_test=None,
    y_test=None,
    ax=None,
    classes=None,
    cmap="YlOrRd",
    support=None,
    encoder=None,
    is_fitted="auto",
    force_model=False,
    show=True,
    colorbar=True,
    fontsize=None,
    **kwargs
)

Import

from yellowbrick.classifier import ClassificationReport
from yellowbrick.classifier.classification_report import classification_report

I/O Contract

Inputs

Name Type Required Description
estimator sklearn classifier Yes A scikit-learn classifier to evaluate
ax matplotlib Axes No Axes object on which to draw the heatmap; uses current axes if not provided
classes list of str No Human-readable class labels for the y-axis of the heatmap
cmap str No Matplotlib colormap name for the heatmap; defaults to "YlOrRd"
support None, True, False, "percent", or "count" No Whether and how to display the support column; defaults to None (hidden)
encoder dict or LabelEncoder No Mapping from target values to human-readable labels
is_fitted bool or str No Whether the estimator is already fitted; defaults to "auto"
force_model bool No If True, skip the classifier type check on the estimator
colorbar bool No If True (default), display a colorbar alongside the heatmap
fontsize int or None No Font size for the cell labels and axis tick labels

Outputs

Name Type Description
score_ float Global accuracy score from the underlying estimator
scores_ dict of dicts Nested dictionary mapping metric names (precision, recall, f1, support) to dictionaries mapping class labels to values
support_score_ ndarray Raw support counts per class before percentage conversion
ax matplotlib Axes The axes with the rendered classification report heatmap

Usage Examples

Basic Usage

from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from yellowbrick.classifier import ClassificationReport
from yellowbrick.datasets import load_occupancy

X, y = load_occupancy()
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

viz = ClassificationReport(GaussianNB(), support="count")
viz.fit(X_train, y_train)
viz.score(X_test, y_test)
viz.show()

Quick Method

from sklearn.naive_bayes import GaussianNB
from yellowbrick.classifier.classification_report import classification_report
from yellowbrick.datasets import load_occupancy

X, y = load_occupancy()
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

classification_report(GaussianNB(), X_train, y_train, X_test, y_test)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment