Skip to content
svgale-plot

Accumulated local effects

What is a feature's effect on predictions when features are correlated?

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

How to read it

  1. Read the curve as the feature's effect, relative to the average prediction.
  2. Read its slope: how predictions change locally.
  3. Check the band for uncertainty, and the rug for where data exists.
  1. Callout 1: Crosses zero: predictions here equal the average.
  2. Callout 2: Higher values lift predictions.
  3. Callout 3: Low values lower them.

Watch out

  • ALE is about the model, not a causal effect.

Defaults

No settings: the chart draws one way.

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.
  • ALE averages prediction differences within each quantile interval (so it never evaluates impossible feature combinations) and centres the accumulated curve to mean zero over the data.
  • Intervals, when present, are the engine's (bootstrap over rows).
# Accumulated local effects — Codesplash Chart Lab (recipe "ale-plot")
# controls: defaults
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("ale-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
X = "daylight (minutes)"
Y = "effect on daily rentals"
LO = "lower"
HI = "upper"
G = None
groups = levels_of(df[G]) if G else [None]
series = []
for name in groups:
    d = df if name is None else df[df[G].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values(X)))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhline(0, color="grey", linewidth=0.8)
for i, (name, d) in enumerate(series):
    col = PALETTE[i % len(PALETTE)]
    if LO and HI:
        ax.fill_between(d[X], d[LO], d[HI], color=col, alpha=0.15, lw=0)
    ax.plot(d[X], d[Y], color=col, linewidth=2, label=name or Y)
ax.set_xlabel(X)
ax.set_ylabel(Y)
if G: ax.legend(fontsize=8)
plt.show()

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