Explainable AI (XAI) Intermediate 13 minutes

Partial Dependence, ICE and ALE Plots

How does the model's prediction change on average when a single feature changes?

Your progress in the track0%

Partial dependence

$$\hat{f}_S(x_S) = \frac{1}{n}\sum_{i=1}^n \hat{f}\big(x_S, x_C^{(i)}\big)$$

We fix the feature \(x_S\) at a value, leave the other features \(x_C\) as they are for each example, then take the average.

Example

import matplotlib.pyplot as plt
from sklearn.datasets import fetch_california_housing
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.inspection import PartialDependenceDisplay
X, y = fetch_california_housing(return_X_y=True, as_frame=True)
model = HistGradientBoostingRegressor(random_state=0).fit(X, y)
PartialDependenceDisplay.from_estimator(model, X.sample(500, random_state=0),
                                        ["MedInc", "AveOccup"], kind="both")   # PDP + ICE
plt.show()

The comparison

PDPICEALE
ScopeGlobalFor each exampleGlobal
Reveals interactionsNoYesPartly (two-way ALE)
With correlated featuresMay misleadMay misleadSafer
Ease of understandingHighMediumMedium

An example of correlation

The features “number of rooms” and “area” are correlated. A PDP for the number of rooms evaluates a 40-square-metre house with ten rooms, a combination that does not exist; ALE compares only houses that are close in number of rooms, within what actually exists.

All these curves describe Model, not the causal relationship in reality.

Lesson terms

Accumulated local effects
A method that measures a feature's effect by accumulating the local differences in the prediction within small intervals of its values.
Partial dependence plot
A plot of the model's average prediction as a function of a single feature after averaging out the effect of the other features.
Individual conditional expectation curves
One line per example showing how its prediction changes when a single feature is changed.

Abstract

The partial dependence plot (PDP) shows the model's average prediction when a feature is fixed at different values for all examples. ICE curves draw one line per example, revealing interactions that the average hides. When features are correlated, PDP evaluates the model on unrealistic combinations, and here accumulated local effects (ALE) curves are safer because they rely on local changes within the data distribution.

Review questions

  1. When is a PDP misleading?

    When there are strong interactions that cancel out in the average, or when features are correlated so the model is evaluated on unrealistic combinations.

  2. What do ICE curves add?

    They show the heterogeneity of the effect across examples, revealing interactions.

Sources and references

  1. scikit-learn — Partial Dependence and ICE plots
  2. Apley & Zhu — Visualizing the Effects of Predictor Variables in Black Box Supervised Learning Models (ALE)
  3. Goldstein et al. — Peeking Inside the Black Box (ICE)

Complete the lesson