Implementation:Scikit learn Scikit learn PartialDependenceDisplay
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Model Inspection |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for visualizing Partial Dependence Plots (PDP) and Individual Conditional Expectations (ICE) provided by scikit-learn.
Description
The PartialDependenceDisplay class provides visualization of partial dependence and individual conditional expectation plots. It displays how one or two features marginally affect model predictions, supporting 1D line plots for single features (with optional ICE curves per sample) and 2D contour plots for feature interactions. The class is typically created via the from_estimator classmethod, which computes partial dependence internally using the partial_dependence function and arranges multiple subplots in a configurable grid layout.
Usage
Use this display class when interpreting black-box model predictions, understanding the marginal effect of features on model output, comparing the effect of different features, or visualizing individual conditional expectations alongside average partial dependence.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/inspection/_plot/partial_dependence.py
Signature
class PartialDependenceDisplay:
def __init__(
self,
pd_results,
*,
features,
feature_names,
target_idx,
deciles,
kind="average",
subsample=1000,
random_state=None,
is_categorical=None,
)
@classmethod
def from_estimator(
cls,
estimator,
X,
features,
*,
sample_weight=None,
categorical_features=None,
feature_names=None,
target=None,
response_method="auto",
n_cols=3,
grid_resolution=100,
percentiles=(0.05, 0.95),
method="auto",
n_jobs=None,
verbose=0,
line_kw=None,
ice_lines_kw=None,
pd_line_kw=None,
contour_kw=None,
ax=None,
kind="average",
subsample=1000,
random_state=None,
centered=False,
custom_values=None,
)
def plot(self, *, ax=None, n_cols=3, line_kw=None, ice_lines_kw=None,
pd_line_kw=None, contour_kw=None, bar_kw=None, heatmap_kw=None,
pdp_lim=None, centered=False)
Import
from sklearn.inspection import PartialDependenceDisplay
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pd_results | list of Bunch | Yes | Results of partial_dependence for each feature set |
| features | list of (int,) or list of (int, int) | Yes | Feature indices for each subplot |
| feature_names | list of str | Yes | Feature names corresponding to indices |
| target_idx | int | Yes | Target class index for multiclass or multioutput |
| deciles | dict | Yes | Decile values for each feature index |
| kind | str or list of str | No | Plot type: average (PDP), individual (ICE), or both (default average) |
| subsample | int | No | Number of ICE lines to display per plot (default 1000) |
| estimator | estimator instance | Yes (from_estimator) | Fitted estimator |
| X | array-like | Yes (from_estimator) | Input data for computing partial dependence |
| n_cols | int | No | Maximum number of columns in the subplot grid (default 3) |
| grid_resolution | int | No | Number of grid points per feature (default 100) |
| method | str | No | Computation method: auto, recursion, brute |
| centered | bool | No | Whether to center ICE/PD curves at first grid point (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| display | PartialDependenceDisplay | Display object with axes_, lines_, deciles_vlines_, figure_, and bounding_ax_ attributes |
Usage Examples
Basic Usage
import matplotlib.pyplot as plt
from sklearn.datasets import make_friedman1
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.inspection import PartialDependenceDisplay
X, y = make_friedman1(random_state=0)
est = GradientBoostingRegressor(n_estimators=100, random_state=0).fit(X, y)
# Plot partial dependence for features 0, 1, and interaction (0, 1)
features = [0, 1, (0, 1)]
PartialDependenceDisplay.from_estimator(
est, X, features, kind="both", n_cols=3
)
plt.suptitle("Partial Dependence Plots")
plt.tight_layout()
plt.show()
# Plot ICE curves centered at the first grid point
PartialDependenceDisplay.from_estimator(
est, X, features=[0, 1], kind="individual", centered=True
)
plt.show()