Skip to content
svgpdp-ice

Partial dependence with ICE

How does the prediction change as one feature changes, on average and for individual rows?

Demo data · seed 20261101 · 1,281 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the bold line as the average prediction at each feature value.
  2. Read the thin lines as individual rows.
  3. If thin lines cross or fan out, the effect differs across rows: look for an interaction.
  1. Callout 1: The bold line: the average effect.
  2. Callout 2: Thin lines: one row each.
  3. Callout 3: A jump in the average: a threshold in the model.

Watch out

  • With correlated features, PDP asks about impossible rows. Use ALE instead.

Defaults

Centre each line at its first value (c-ICE)
Off
Start every line at zero so differences in shape stand out from differences in level.

Pinned in the code

  • Draws the run's numbers as given (computed by the host's cs-ml evaluation or the Python/R engine); the chart computes nothing statistical.
  • The grid is the engine's (training quantiles of the feature); the PDP is the mean of the ICE curves over the explained rows.
  • Beyond 200 ICE lines the chart draws every k-th line (deterministic) and says so in the legend.
  • PDPs extrapolate into impossible combinations when features are correlated — prefer ALE then.
# Partial dependence with ICE — Codesplash Chart Lab (recipe "pdp-ice")
# controls: centered=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("pdp-ice-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["pdp", "ice"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
X = "BMI"
YH = "predicted probability"
LINE = "line"
KIND = "kind"
CENTERED = False  # c-ICE: each curve minus its value at the smallest x
d = df.dropna(subset=[X, YH, LINE]).sort_values(X)
kind = d[KIND].astype(str).str.lower() if KIND else pd.Series("ice", index=d.index)
ice, pdp = d[kind == "ice"], d[kind == "pdp"]
if pdp.empty:  # no PDP rows: the PDP is the mean of the ICE curves
    pdp = ice.groupby(X, as_index=False)[YH].mean().assign(**{LINE: "PDP"})
def centre(frame):
    return frame.assign(_y=frame[YH] - frame.groupby(LINE, observed=True)[YH].transform("first")) if CENTERED else frame.assign(_y=frame[YH])
ice, pdp = centre(ice), centre(pdp)
fig, ax = plt.subplots(figsize=(8, 4.5))
for _, s in ice.groupby(LINE, observed=True):
    ax.plot(s[X], s["_y"], color=GREY, linewidth=0.6, alpha=0.7)
ax.plot(pdp[X], pdp["_y"], color=PALETTE[0], linewidth=2.8, label="partial dependence")
ax.set_xlabel(X)
ax.set_ylabel(("centred " if CENTERED else "") + YH)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads pdp-ice-demo.csv · app theme from the optional codesplash helper