Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PermutationImportance

Utility sklearn-compatible ⚙️ Model Selection

Permutation importance — feature importance by permuting each column and measuring score drop. / Importance par permutation — importance des features en permutant chaque colonne et mesurant la baisse de score.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, json, numpy as np
X = np.random.randn(200, 5)
y = X @ [2, -1, 0, 0.5, 1.2] + np.random.randn(200) * 0.3
model = sp.Ridge(alpha=0.5)
model.fit(X, y)
imp = sp.permutation_importance(model, X, y, n_repeats=5)
print(imp.importances_mean_)
💡
EN — Drop-in replacement: sp.PermutationImportance has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_permutation_importance — aliases: permutation_importance

Python class
sp.PermutationImportance(n_repeats=10, scoring=auto)
Constructor Parameters
ParameterTypeDefaultDescription
n_repeatsint10Number of permutations per feature.
scoringstrautoScoring metric: auto-detects cls/reg.
Returns

JSON with importances_mean, importances_std per feature.

Algorithm

$$\text{imp}j = \bar{s} - \frac{1}{K}\sum{k=1}^{K} s(\text{perm}_k(X_j))$$

Example
import seraplot as sp, json, numpy as np
X = np.random.randn(200, 5)
y = X @ [2, -1, 0, 0.5, 1.2] + np.random.randn(200) * 0.3
model = sp.Ridge(alpha=0.5)
model.fit(X, y)
imp = sp.permutation_importance(model, X, y, n_repeats=5)
print(imp.importances_mean_)

Référence API

Nom de fonction JSON

ml_permutation_importance — alias : permutation_importance

Classe Python
sp.PermutationImportance(n_repeats=10, scoring=auto)
Paramètres du constructeur
ParamètreTypeDéfautDescription
n_repeatsint10Nombre de permutations par feature.
scoringstrautoMétrique de scoring : auto-détecte cls/reg.
Retourne

JSON avec importances_mean, importances_std par feature.

Algorithme

$$\text{imp}j = \bar{s} - \frac{1}{K}\sum{k=1}^{K} s(\text{perm}_k(X_j))$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(200, 5)
y = X @ [2, -1, 0, 0.5, 1.2] + np.random.randn(200) * 0.3
model = sp.Ridge(alpha=0.5)
model.fit(X, y)
imp = sp.permutation_importance(model, X, y, n_repeats=5)
print(imp.importances_mean_)