Skip to content
svgimportance-bar

Feature importance

Which features does the model rely on most?

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

How to read it

  1. Read bar length as how much the model relies on that feature.
  2. Check the whiskers: overlapping features may not really differ.
  3. Check which kind of importance is on the axis.
  1. Callout 1: The top feature.
  2. Callout 2: Whisker: how much it varies across repeats.
  3. Callout 3: Near zero: the model barely uses these.

Watch out

  • Importance doesn't mean causal, and correlated features share or swap importance.

Defaults

Features shown
20
How many features to show, largest first.
Range 3 to 60, step 1

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.
  • Ranked by |importance|; negative permutation importance (the model did better with the feature shuffled) is drawn left of zero in a second colour.
  • Importance kinds are not comparable across methods: gain counts splits, permutation measures the metric drop, SHAP the mean absolute contribution — the axis label names the kind.
  • Correlated features share importance; a low value does not mean the feature carries no information.
# Feature importance — Codesplash Chart Lab (recipe "importance-bar")
# controls: top=20
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("importance-bar-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=["tenure (months)", "monthly charges", "contract=month-to-month", "support calls", "total charges", "payment=electronic check", "age", "internet=fiber", "streaming TV", "paperless billing", "dependents", "region=north"])

FEAT = "feature"
IMP = "drop in ROC AUC"
LO = "lower"
HI = "upper"
TOP = 20
d = df.dropna(subset=[FEAT, IMP]).sort_values(IMP, ascending=False).head(TOP).iloc[::-1]  # largest at the top
fig, ax = plt.subplots(figsize=(8, 0.32 * len(d) + 1.2))
err = [d[IMP] - d[LO], d[HI] - d[IMP]] if LO and HI else None
ax.barh(d[FEAT].astype(str), d[IMP], xerr=err, color=PALETTE[0], ecolor="grey", capsize=2)
ax.axvline(0, color="grey", linewidth=0.8)
ax.set_xlabel(IMP)
plt.show()

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