Skip to content
svggam-partial

GAM partial effects

What does each feature add to an additive model's prediction?

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

How to read it

  1. Read each panel as one feature: how far it moves the prediction above or below average as its value changes.
  2. Check the shaded band, about two standard errors: where it covers the dashed zero line, the data can't tell the effect from none.
  3. Compare heights across panels. They share one y axis, so a taller curve is a larger effect.
  1. Callout 1: A steep stretch: the feature matters most here.
  2. Callout 2: Dashed line: the average prediction.
  3. Callout 3: The band widens at the edges, where there are fewer rows.

Watch out

  • Effects are on the model's link scale: log-odds or log for binary, Poisson, Gamma and Tweedie models, not the original units.
  • A partial effect describes this model holding the others fixed. With correlated features it isn't 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.
  • Effects are centred on the training rows, on the link scale (response, log-odds or log). The band is ±2 standard errors of the smooth from the penalized fit's covariance. All panels share one y axis, so curve heights compare directly.
# GAM partial effects — Codesplash Chart Lab (recipe "gam-partial")
# 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("gam-partial-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["Feature"] = pd.Categorical(df["Feature"].astype("string"), categories=["Temperature", "Wind", "Solar radiation"])

_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")
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)))
F = "Feature"
X = "Value"
E = "Effect"
L = "Lower"
U = "Upper"
groups = levels_of(df[F]) if F else [None]
series = []
for name in groups:
    d = df if name is None else df[df[F].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values([X], kind="mergesort")))
n = len(series)
cols = min(n, 3)
rows = int(np.ceil(n / cols))
fig, axes = plt.subplots(rows, cols, figsize=(3.4 * cols, 2.6 * rows), sharey=True, squeeze=False)
for ax in axes.flat[n:]:
    ax.set_visible(False)
for ax, (name, d) in zip(axes.flat, series):
    d = d.dropna(subset=[X, E]).sort_values(X)
    ax.axhline(0, color=REF, linestyle="--", linewidth=1)
    if L and U:
        ax.fill_between(d[X], d[L], d[U], color=PALETTE[0], alpha=0.16, linewidth=0)
    ax.plot(d[X], d[E], color=PALETTE[0], linewidth=2)
    ax.set_title(name, fontsize=10, loc="left")
for ax in axes[:, 0]:
    ax.set_ylabel(E)
fig.tight_layout()
plt.show()

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