150 samples are generated from a known linear process, then a small linear-regression model ŷ = w₀ + w₁f₁ + w₂f₂ + w₃f₃ is fit to them by ordinary least squares (closed-form normal equations, solved with Gaussian elimination — this is the exact "black box" being explained).
Permutation importance for feature j:
MSE_base = mean( (ŷ(X) − y)² )
MSE_perm_j = mean( (ŷ(X_perm_j) − y)² ) [column j shuffled, others untouched]
Importance_j = mean over K shuffles of (MSE_perm_j − MSE_base)
Shuffling a feature that the model actually relies on destroys the correlation it needs and prediction error jumps — a large Δ. Shuffling a feature the model barely uses changes almost nothing — Δ stays near zero. This is model-agnostic: it never looks inside the model, only at how its error responds to breaking one input's relationship to the rest.
- f1 / f2 / f3 buttons — choose which feature column gets shuffled.
- Shuffle repeats — permutation importance is noisy for a single shuffle, so K independent shuffles are run and averaged, as scikit-learn's
permutation_importance does.
- Run Permutation Test — performs the shuffle-and-reevaluate cycle; every point in the cloud recolors from green (low error) to red (high error) using the model's prediction under the permuted feature.
- The true data-generating weights are 3.0, −2.0 and 0.15 for f1, f2, f3 — so a correct permutation test should rank f1 > f2 ≫ f3, even though the fitted model never sees those numbers directly.
Real-world relevance: this is the workhorse interpretability technique used whenever SHAP is too slow to run on a large tabular model — it works on any fitted predictor without retraining, and is the default "which feature matters" answer in most production ML monitoring dashboards.