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 ClassificationScoreVisualizer

From Leeroopedia


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

Overview

Concrete base class for all Yellowbrick classification visualizers that wraps a scikit-learn classifier and provides common infrastructure for visual model evaluation.

Description

The ClassificationScoreVisualizer class is the base class from which all Yellowbrick classification visualizers inherit. It extends ScoreVisualizer to add classification-specific functionality: verifying the wrapped estimator is a classifier, managing class labels and class counts extracted from the target vector during fit, resolving categorical colors for class-based visualizations, supporting label encoding through an encoder parameter or explicit class name lists, and computing the base estimator score during the score call.

The class provides three core methods that subclasses typically override. The fit method fits the underlying estimator and extracts the unique class labels and their counts from the target vector. It also reconciles class labels between the target vector and the estimator's own classes_ attribute when they differ. The score method computes the underlying estimator's default score (typically accuracy) and handles the case where the visualizer is instantiated with a pre-fitted estimator that was not fit through the visualizer. The class_colors_ property dynamically generates a categorical color palette with one color per class.

This class does not produce its own visualization; it is the responsibility of concrete subclasses (such as ROCAUC, ClassificationReport, ConfusionMatrix, PrecisionRecallCurve, ClassPredictionError) to implement the draw method and extend score with specific metric computation and rendering logic.

Usage

ClassificationScoreVisualizer is not used directly by end users. It is used as the base class when implementing new classification visualizers in the Yellowbrick library. Understanding its API is important for extending the library or for debugging visualizer behavior.

Code Reference

Source Location

  • Repository: yellowbrick
  • File: yellowbrick/classifier/base.py
  • Lines: L109-239 (ClassificationScoreVisualizer class)

Signature

class ClassificationScoreVisualizer(ScoreVisualizer):
    def __init__(
        self,
        estimator,
        ax=None,
        fig=None,
        classes=None,
        encoder=None,
        is_fitted="auto",
        force_model=False,
        **kwargs
    )

    def fit(self, X, y=None, **kwargs)

    def score(self, X, y)

Import

from yellowbrick.classifier.base import ClassificationScoreVisualizer

I/O Contract

Inputs

Name Type Required Description
estimator sklearn classifier Yes A scikit-learn classifier; raises YellowbrickTypeError if not a classifier (unless force_model is True)
ax matplotlib Axes No Axes object for plotting; uses current axes if not provided
fig matplotlib Figure No Figure object for plotting; uses current figure if not provided
classes list of str No Human-readable class labels; if not provided, extracted from the target vector during fit
encoder dict or LabelEncoder No Mapping from raw class values to human-readable labels; takes precedence over classes for label decoding
is_fitted bool or str No Whether the estimator is already fitted; defaults to "auto" (auto-detection)
force_model bool No If True, skip the classifier type check; useful for non-standard estimators

Outputs

Name Type Description
score_ float The underlying estimator's score on the test data (typically accuracy)
classes_ ndarray Array of unique class labels extracted from the training target, optionally decoded via encoder
class_counts_ ndarray or None Array of per-class instance counts from the training target; None if the visualizer was not fit directly
class_colors_ list Property returning a list of colors, one per class, resolved from the matplotlib color cycle

Usage Examples

Basic Usage

# ClassificationScoreVisualizer is typically not used directly.
# It is subclassed by concrete visualizers such as:
from yellowbrick.classifier import ROCAUC
from yellowbrick.classifier import ConfusionMatrix
from yellowbrick.classifier import ClassificationReport

# Example of how a subclass uses the base:
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from yellowbrick.classifier import ConfusionMatrix
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)

# ConfusionMatrix inherits from ClassificationScoreVisualizer
viz = ConfusionMatrix(SVC(), classes=["not_occupied", "occupied"])
viz.fit(X_train, y_train)   # calls ClassificationScoreVisualizer.fit
viz.score(X_test, y_test)   # calls ClassificationScoreVisualizer.score, then ConfusionMatrix.score
viz.show()

Quick Method

# No quick method exists for the base class.
# Each concrete subclass provides its own quick method:
# - roc_auc()
# - classification_report()
# - confusion_matrix()
# - precision_recall_curve()
# - discrimination_threshold()
# - class_prediction_error()

Related Pages

Implements Principle

Requires Environment

Page Connections

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