Skip to content
svgh-statistic

Friedman's H interactions

Which features does the model combine, rather than use one at a time?

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

How to read it

  1. Read each cell as how much of a pair's joint effect is interaction: 0 means the pair adds up.
  2. Read the outlined diagonal as each feature against all the others.
  3. Look at the partial dependence of any high pair to see what the interaction does.

Watch out

  • H is noisy with few rows and can be large for pairs whose total effect is tiny, so check their importance too.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the explanation the Python or R engine computed; the chart computes nothing statistical.
  • H is the square root of H², the share of the joint partial dependence's variance that the separate effects do not explain.
  • The colour scale runs from 0 to the largest H in the chart; a large H can still describe a small effect, so read it next to the partial dependence.
# Friedman's H interactions — Codesplash Chart Lab (recipe "h-statistic")
# 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("h-statistic-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=["glucose", "BMI", "age", "pedigree"])
df["with"] = pd.Categorical(df["with"].astype("string"), categories=["glucose", "BMI", "age", "pedigree"])

_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")
A = "feature"
B = "with"
H = "H"
feats = list(dict.fromkeys(list(df[A].astype(str)) + list(df[B].astype(str))))
m = pd.DataFrame(np.nan, index=feats, columns=feats)
for a, b, h in zip(df[A].astype(str), df[B].astype(str), df[H]):
    m.loc[a, b] = h; m.loc[b, a] = h  # the diagonal: each feature against all the others
fig, ax = plt.subplots(figsize=(5.5, 5))
im = ax.imshow(m.to_numpy(dtype=float), cmap="Blues", vmin=0)
ax.set_xticks(range(len(feats)), feats, rotation=45, ha="right")
ax.set_yticks(range(len(feats)), feats)
for i in range(len(feats)):
    for j in range(len(feats)):
        if pd.notna(m.iat[i, j]):
            ax.text(j, i, f"{m.iat[i, j]:.2f}", ha="center", va="center", fontsize=8)
fig.colorbar(im, label="Friedman's H")
plt.show()

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