Skip to content
svgshap-dependence

SHAP dependence

How does one feature's value change its contribution, and does another feature modify it?

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

How to read it

  1. Read the shape: how a feature's value changes its contribution.
  2. Read the vertical spread at one value: another feature is modifying it.
  3. Read the colour to see which one.
  1. Callout 1: Crossing zero: the feature's effect flips sign here.
  2. Callout 2: Rising with age.
  3. Callout 3: Colour scale: the interacting feature.

Watch out

  • Few rows at the extremes make those shapes unreliable.

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.
  • The engine picks the colour feature (the strongest SHAP interaction, as the shap library does) or the user does; numeric colours run on a sequential ramp, categories on the categorical palette.
  • Vertical spread at a fixed x is the effect of other features — colour separating that spread suggests an interaction.
# SHAP dependence — Codesplash Chart Lab (recipe "shap-dependence")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

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("shap-dependence-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_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")
V = "age (years)"
SHAP = "SHAP value (log-odds)"
COL = "BMI"
d = df.dropna(subset=[V, SHAP])
fig, ax = plt.subplots(figsize=(7, 4.8))
ax.axhline(0, color="grey", linewidth=0.8)
cmap = LinearSegmentedColormap.from_list("shap", [DIV[-1], DIV[0]])
sc = ax.scatter(d[V], d[SHAP], c=d[COL] if COL else PALETTE[0], cmap=cmap if COL else None, s=14, alpha=0.8)
if COL:
    fig.colorbar(sc, ax=ax, label=COL)
ax.set_xlabel(V)
ax.set_ylabel(SHAP)
plt.show()

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