Permutation Feature Importance
Intuition
If shuffling a feature's column (destroying its relationship with the target) makes the model much worse, the model relied on that feature. If nothing changes, the feature didn't matter to this model.
Precise explanation
- Baseline score (higher = better, e.g. R² or accuracy).
- For each feature and repeat : permute column j (rows shuffled with
rng.permutation(n)), compute . - Importance , with standard deviation across repeats.
Use one generator
default_rng(seed), iterating features in order and repeats inside. Small negative values mean "no importance" (noise). Correlated features share importance — permuting one can be compensated by the other. Computing on held-out data measures importance for generalisation.
Worked example
y = 3x₀ + noise, x₁ pure noise, linear model: permuting x₀ drops R² from ≈1 to ≈−1; permuting x₁ ≈ 0.
Common mistakes
- Re-fitting the model after permuting (that is drop-column importance, a different method).
- Permuting all features at once.
- Reporting a single permutation without variability.
Why this matters
Model-agnostic, cheap and widely used (scikit-learn permutation_importance); it also connects to the
permutation test idea from ST-20.
Library implementation
sklearn.inspection.permutation_importance(estimator, X, y, n_repeats=..., random_state=...)
implements the same algorithm for fitted scikit-learn models (and pipelines). It uses its own
random shuffles, so individual numbers differ slightly from yours, but the ranking of clearly
important features agrees. The comparison runs when scikit-learn is installed.
References
- Interpretable Machine Learning (3rd edition) — Christoph Molnar (
S024) - User Guide (scikit-learn 1.9.1) — scikit-learn developers (
S012)