Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn DecisionBoundaryDisplay

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Visualization
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for visualizing decision boundaries of classifiers and regressors provided by scikit-learn.

Description

The DecisionBoundaryDisplay class visualizes the decision boundary of a fitted estimator by evaluating model predictions on a dense grid over the feature space. It supports classifiers, regressors, clusterers, and outlier detectors, using appropriate response methods (decision_function, predict_proba, or predict) depending on the estimator type. The display renders as filled contour plots, contour line plots, or pseudocolor plots on 2D feature spaces.

Usage

Use this display class when visualizing how a classifier separates classes in a 2D feature space, comparing decision boundaries of different models, or for educational purposes to illustrate how different algorithms partition the feature space.

Code Reference

Source Location

Signature

class DecisionBoundaryDisplay:
    def __init__(self, *, xx0, xx1, response)
    def plot(self, plot_method="contourf", ax=None, xlabel=None, ylabel=None, **kwargs)
    @classmethod
    def from_estimator(
        cls,
        estimator,
        X,
        *,
        grid_resolution=100,
        eps=1.0,
        plot_method="contourf",
        response_method="auto",
        class_of_interest=None,
        xlabel=None,
        ylabel=None,
        ax=None,
        **kwargs,
    )

Import

from sklearn.inspection import DecisionBoundaryDisplay

I/O Contract

Inputs

Name Type Required Description
xx0 ndarray of shape (grid_resolution, grid_resolution) Yes First output of numpy meshgrid
xx1 ndarray of shape (grid_resolution, grid_resolution) Yes Second output of numpy meshgrid
response ndarray of shape (grid_resolution, grid_resolution) Yes Model response values on the grid
estimator estimator instance Yes (from_estimator) Fitted estimator
X array-like of shape (n_samples, 2) Yes (from_estimator) Input data with exactly 2 features
grid_resolution int No Number of grid points per axis (default 100)
eps float No Extends grid range beyond data limits by this factor (default 1.0)
plot_method str No Plot type: contourf, contour, or pcolormesh (default contourf)
response_method str No Prediction method: auto, decision_function, predict_proba, predict
class_of_interest int, float, bool or str No Class to plot for multiclass classifiers

Outputs

Name Type Description
display DecisionBoundaryDisplay Display object with surface_, ax_, and figure_ attributes

Usage Examples

Basic Usage

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.inspection import DecisionBoundaryDisplay
from sklearn.svm import SVC

# Load data (use only first 2 features for 2D visualization)
iris = load_iris()
X = iris.data[:, :2]
y = iris.target

# Fit classifier
clf = SVC(kernel="rbf", gamma=2, C=1).fit(X, y)

# Plot decision boundary
disp = DecisionBoundaryDisplay.from_estimator(
    clf, X, grid_resolution=200, plot_method="contourf",
    response_method="predict", alpha=0.5
)
disp.ax_.scatter(X[:, 0], X[:, 1], c=y, edgecolors="k", s=20)
plt.show()

Related Pages

Page Connections

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