Foundations to Frontier
Tests
D. Classical Machine Learning › D17 Interpretability for Classical Models

Partial Dependence and ICE Plots

Partial dependence plots (Friedman, 2001) show how a model's average prediction changes as one feature is varied while the other features keep their observed values. Individual conditional expectation (ICE) plots (Goldstein, Kapelner, Bleich and Pitkin, 2015) show the same thing row by row, one curve per data point, so they reveal when different rows respond differently, which is the signature of an interaction that the average hides. Both are model-agnostic and easy to compute, but both ask the model about combinations of feature values that may never occur in the data: when features are correlated, the model is forced to extrapolate and the plots can mislead. Accumulated local effects (ALE; Apley and Zhu, 2020) reduce this by averaging local prediction changes within the data's own distribution. This page covers PDP and ICE computation, centred and derivative ICE, two-way PDPs and Friedman's H-statistic, the extrapolation problem, ALE, and how to read these plots honestly. In the exercises you build PDP and ICE for a numpy random forest and detect an interaction, then compare PDP, ALE and a linear model when correlated features have opposite effects.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Turn one dial and watch the output

To understand a complicated machine, you can turn one dial slowly through its range, with everything else left as it is, and watch what the output does. Do that for many starting states and you get ICE curves, one per state. Average them and you get the partial dependence plot (PDP). The PDP gives the typical effect of that dial; the ICE curves show whether everyone responds the same way.

Partial dependence and ICE: the average and the individuals
−0.9 ← feature value → 0.9
ICE slopes: mean 1.12, spread (sd) 0.98 across the 60 rows
For x0 the curves are parallel, so the PDP tells the whole story. For x2 the PDP shows a moderate average slope, but the ICE curves split into two families: steep for rows with x3 > 0 (orange) and flat otherwise. That is an interaction, and the average describes nobody. For x3 the PDP is nearly flat, yet each curve jumps up or down at 0 by an amount that depends on x2. The forest also smooths the true shapes: slopes come out a little below their true values, and the x² curve is flattened.
Why engineers care

PDPs and ICE plots answer the questions engineers ask about a black-box model: “If temperature rises, does predicted wear go up? Smoothly or past a threshold? The same for every machine?” They are standard in model reviews. They can also mislead in specific, known ways, which reviewers need to recognise.

📝 Quick check (Level 0)
0/3 answered
  1. 1. An ICE curve shows…
  2. 2. The PDP is…
  3. 3. ICE curves that fan out in different directions suggest…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Computing them by hand

ICE. For each row i and grid value v, set xⱼ = v in that row (keeping its other features) and predict. Curve i is v ↦ f(v, x₍ᵢ,₋ⱼ₎).

PDP. PD(v) = (1/n) Σᵢ f(v, x₍ᵢ,₋ⱼ₎), the pointwise mean of the ICE curves. Two ICE curves (0, 3, 6) and (0, 0, 0) average to the PDP (0, 1.5, 3): slope 1.5, which describes neither row.

Centred ICE (c-ICE). Subtract each curve’s value at the first grid point. Curves (2, 3, 5) and (1, 1, 1) become (0, 1, 3) and (0, 0, 0). Differences in level disappear, and differences in shape remain.

Heterogeneity. The spread of per-row slopes summarises how much the curves disagree. Slopes 3 and 0 have sd 1.5; parallel curves have sd 0.

Cost. n rows × G grid points predictions per feature: 150 × 10 = 1500 for each plot.

📝 Quick check (Level 1)
0/3 answered
  1. 1. ICE curves (1, 2) and (3, 6) give a PDP of…
  2. 2. Centring removes…
  3. 3. Predictions needed for 200 rows and 20 grid points?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

What the average hides

Exercise 1 (random forest fitted to y = 2x₀ + x₁² + 3x₂·[x₃ > 0] + noise, features uniform on [−1, 1]; ICE for 150 rows on a 10-point grid).

feature true average slope PDP slope PDP range sd of ICE slopes mean ICE slope: x₃ > 0, x₃ ≤ 0
x₀ 2 (linear) +1.81 3.01 0.17 +1.83, +1.78
x₁ 0 overall (U-shaped x²) −0.06 0.35 0.09 −0.03, −0.09
x₂ 1.5 (3 if x₃ > 0, else 0) +1.35 2.35 1.17 +2.51, +0.22
x₃ 0 (a jump of 3x₂ at 0) +0.14 0.22 1.17 –
  • x₀: parallel curves (sd 0.17), so the PDP is the whole story. The forest’s smoothing shrank the slope slightly, from 2 to 1.81.
  • x₂: the PDP shows a moderate average slope, but the ICE curves split by the sign of x₃: about 2.5 for one group and 0.2 for the other. The average describes neither group.
  • x₃: the PDP is almost flat, because the jumps of +3x₂ and −3x₂ cancel on average. Yet every ICE curve has a step at 0, and the large slope spread exposes it.
  • x₁: the U-shape survives in the PDP but is flattened, with a range of 0.35 against a true range of 0.81 on the grid.

Two-way PDP and the H-statistic. PD₍ⱼₖ₎(u, v) varies two features together. Friedman’s H² measures the share of PD₍ⱼₖ₎’s variance not explained by PDⱼ + PDₖ, which is 0 if there is no interaction.

from sklearn.inspection import PartialDependenceDisplay
PartialDependenceDisplay.from_estimator(model, X, features=[2], kind="both", centered=True)   # PDP + ICE
🐍 Exercise 1: PDP and ICE
Fit a numpy random forest, compute ICE curves, the PDP and centred ICE for each feature, and use the spread of ICE slopes to detect an interaction.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The PDP of x₃ was nearly flat because…
  2. 2. The sd of ICE slopes for x₂ was about…
  3. 3. The forest's PDP slope for x₀ (true 2) was…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Extrapolation and ALE

The problem. The PDP at xⱼ = v averages over all rows’ other features, including rows where v is impossible given those features (for example, a high altitude with a sea-level air pressure). With correlated features, many of the evaluated points lie off the data. Tree models are flat there, other models arbitrary, so the PDP reflects extrapolation rather than learned behaviour.

M-plots average predictions only over rows near v. But then they mix in the effects of correlated features, so they are not the effect of xⱼ alone.

Accumulated local effects (ALE).

  1. Split xⱼ into quantile bins.
  2. For the points in bin k, compute the mean of f(upper edge, x₋ⱼ) − f(lower edge, x₋ⱼ). This is a small move that stays near the data.
  3. Accumulate across bins and centre.

ALE avoids most extrapolation and isolates xⱼ’s own effect, at the price of being harder to explain and noisier with few points per bin. For f = 2x₀ + x₀x₁, the local slope in x₀ is 2 + x₁. In a bin of width 0.3 containing points with x₁ = 1 and 3, the bin effect is 0.3 × 4 = 1.2.

PDP for additive parts. If f(x) = g(xⱼ) + h(x₋ⱼ), the PDP equals g plus a constant, exactly. Interactions and extrapolation are what make PDPs hard to read.

Interview questions.

  • When are PDPs trustworthy? When the feature is roughly independent of the others, and the ICE curves are roughly parallel.
  • What does a PDP not tell you? Causation (it describes the model), and heterogeneity (use ICE).
📝 Quick check (Level 3)
0/3 answered
  1. 1. PDPs can mislead with correlated features because…
  2. 2. ALE computes…
  3. 3. For an additive model, the PDP of xⱼ equals…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

When correlated features have opposite effects

History.

  • J. Friedman (2001) introduced partial dependence plots with gradient boosting.
  • J. Friedman and B. Popescu (2008) introduced the H-statistic.
  • A. Goldstein, A. Kapelner, J. Bleich and E. Pitkin (2015) introduced ICE plots.
  • D. Apley and J. Zhu (2020) introduced accumulated local effects.

Exercise 2. y = x₀ + b·x₁ + noise with corr(x₀, x₁) = ρ. The true effect of x₀ is +1 throughout. Forest of 25 trees with leaf size 5, n = 500, 2 datasets.

b ρ forest PDP slope forest ALE slope linear-model coefficient
+1 0 +0.90 +0.91 +1.00
+1 0.9 +0.97 +1.00 +1.01
+1 0.99 +0.98 +1.02 +1.05
−1 0 +0.93 +0.94 +1.00
−1 0.9 +0.41 +0.71 +1.01
−1 0.99 +0.11 +0.28 +1.05
  • Same-sign effects were easy. With b = +1, y depends on roughly x₀ + x₁, which varies strongly along the data, and every method was close to 1.
  • Opposite effects broke the forest. With b = −1 and ρ = 0.99, y depends on x₀ − x₁, a tiny difference between almost equal features. The forest never learned to separate them, and its PDP showed almost no effect of x₀ (0.11). The PDP also asked the forest about points off the narrow diagonal, where it had no data.
  • ALE was better but far from right (0.28): it avoids extrapolation, but it cannot fix a model that did not learn the effect.
  • A correctly specified linear model recovered +1. The fault lay in the fitted model’s limits, and the plots faithfully showed the model, not the truth.
🐍 Exercise 2 (research): PDP, ALE and correlated features
Estimate the slope of x0's effect (truth +1) with the forest's PDP, the forest's ALE and a linear model, for correlated features with same-sign and opposite-sign effects.

PDP and ICE in AI, robotics and aerospace

  • Model reviews: show how predicted remaining life depends on load, temperature and cycles, with ICE to reveal fleet subgroups that respond differently.
  • Envelope checks: verify that a learned controller’s output varies monotonically and plausibly with key inputs inside the operating envelope.
  • Caution with correlated flight parameters (altitude and pressure, speed and dynamic pressure): prefer ALE or conditional plots, and mark regions without data.

References

  1. J. H. Friedman (2001). “Greedy function approximation: a gradient boosting machine.” Annals of Statistics 29(5).
  2. A. Goldstein, A. Kapelner, J. Bleich, E. Pitkin (2015). “Peeking inside the black box: visualizing statistical learning with plots of individual conditional expectation.” JCGS 24(1).
  3. D. W. Apley, J. Zhu (2020). “Visualizing the effects of predictor variables in black box supervised learning models.” JRSS B 82(4).
  4. J. H. Friedman, B. E. Popescu (2008). “Predictive learning via rule ensembles.” Annals of Applied Statistics 2(3).
  5. C. Molnar (2022). Interpretable Machine Learning, 2nd ed.