3.2. Permutation Feature Importance#
Permutation Feature Importance (PFI) is a model-agnostic approach for quantifying the relevance of individual or groups of features in predictive models. It was initially introduced as the mean decrease in accuracy (MDA) by Breiman[1] for Random Forests. It is a perturbation-based method that compares the predictive performance of a model on unmodified test data—following the same distribution as the training data— to its performance when the studied feature is marginally permutated. Thus, this approach does not require retraining the model contrary to other methods such as Leave-One-Covariate-Out.
3.2.1. Theoretical index#
The target quantity estimated by PFI can be defined as:
where \(X^{\pi(j)}\) corresponds to the input distribution where the \(j^{th}\) feature has been replaced by a marginally independent \(X^j\). Then, it preserves the same marginal distribution \(P(X_j)\) but is independent of the other features and the output.
Note
Uninteresting theoretical target
It was initially proposed as an heuristic Variable Importance Measure and not as a formal estimator of a interesting theoretical quantity. Moreover, it was shown in Bénard et al.[2] that PFI estimates a quantity that is not interpretable. They proved that it can be decomposed as the sum of the Total Sobol Index (TSI) Generalized Total Sobol Index and two extra terms that are not significant due to correlations. Thus, the theoretical quantity estimated by PFI is not a relevant quantity contrarily to Leave-One-Covariate-Out or Conditional Feature Importance.
3.2.2. Estimation procedure#
The estimation of the PFI is relatively simple since there is no need of retraining any model as happens with other methods such as Leave-One-Covariate-Out or estimating a conditional sampler as in Conditional Feature Importance. A simple permutation of the feature values across the individuals is sufficient since the distribution from which we are sampling is the marginal distribution of the feature, thus breaking the relationship with the others. Also, note that the same estimated model is used for predicting both the original and perturbed datasets.
Note
Extrapolation issues
When features are correlated, permuting a feature can lead to unrealistic combinations of feature values that were not observed in the training data. This can result in the model making predictions in regions of the feature space where it has not been trained, leading to unreliable importance estimates. This issue is discussed in Strobl et al.[3], Hooker et al.[4].
3.2.3. Inference#
Doing inference with PFI is challenging due to the extrapolation issues mentioned above. The distribution of the loss differences is difficult to characterize. Then, obtaining valid p-values for the null hypothesis
is not straightforward. This leads to many false discoveries, especially when features are correlated.
The conditional version of the PFI (Conditional Feature Importance) tackles both issues of extrapolation and of inference by using conditional sampling instead of the marginal permutation.
3.2.4. Regression example#
The following example illustrates the use of PFI on a regression task with:
>>> from sklearn.datasets import make_regression
>>> from sklearn.linear_model import LinearRegression
>>> from sklearn.model_selection import train_test_split
>>> from hidimstat import PFI
>>> X, y = make_regression(n_features=2)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y)
>>> model = LinearRegression().fit(X_train, y_train)
>>> pfi = PFI(estimator=model)
>>> pfi = pfi.fit(X_train, y_train)
>>> features_importance = pfi.importance(X_test, y_test)
3.2.5. Classification example#
To measure feature importance in a classification task, a classification loss should be used, in addition, the prediction method of the estimator should output the corresponding type of prediction (probabilities or classes). The following example illustrates the use of PFI on a classification task:
>>> from sklearn.datasets import make_classification
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.linear_model import LinearRegression
>>> from sklearn.metrics import log_loss
>>> from sklearn.model_selection import train_test_split
>>> from hidimstat import PFI
>>> X, y = make_classification(n_features=4)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y)
>>> model = RandomForestClassifier().fit(X_train, y_train)
>>> pfi = PFI(
... estimator=model,
... loss=log_loss,
... method="predict_proba",
... )
>>> pfi = pfi.fit(X_train, y_train)
>>> features_importance = pfi.importance(X_test, y_test)