Variable Importance


In-depth Articles

Introduction

After building a model, understanding which features matter most is crucial for interpretation, feature engineering, and model simplification. Variable importance quantifies each feature's contribution to predictive performance.

There is no single "correct" way to measure importance — different methods answer different questions and may yield different rankings. Below we survey the most common approaches, from model-specific to fully model-agnostic.




Model-Specific Methods

Linear Models

In a linear regression \(y = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p + \varepsilon\), the natural measure of importance for feature \(j\) is the absolute value of the t-statistic:

\[ \text{Importance}(j) = \left| \frac{\hat\beta_j}{\text{SE}(\hat\beta_j)} \right| = |t_j| \]

To compare coefficients across features measured on different scales, use standardized coefficients:

\[ \hat\beta_j^{\text{std}} = \hat\beta_j \cdot \frac{s_{x_j}}{s_y} \]

where \(s_{x_j}\) and \(s_y\) are the sample standard deviations of feature \(j\) and the response, respectively.

Tree-Based Models — Mean Decrease in Impurity (MDI)

For tree-based models (CART, Random Forest, Gradient Boosting), Mean Decrease in Impurity measures the total reduction in the splitting criterion (Gini impurity for classification, RSS for regression) attributed to splits on variable \(j\), averaged over all trees:

\[ \text{Imp}(j) = \sum_{t:\, \text{split on } j} \Delta I(t) \cdot p(t) \]

where:

  • \(\Delta I(t)\) = reduction in impurity at node \(t\)
  • \(p(t) = n_t / N\) = proportion of samples reaching node \(t\)

For an ensemble of \(B\) trees, the final importance is averaged: \(\text{Imp}(j) = \frac{1}{B} \sum_{b=1}^{B} \text{Imp}_b(j)\).

Caveat: MDI is biased towards high-cardinality features and features with many possible split points.

Random Forest — Mean Decrease Accuracy (MDA)

Also known as permutation importance computed on the Out-of-Bag (OOB) samples:

  1. For each tree \(b\), compute OOB accuracy \(\text{Acc}_b\)
  2. Permute feature \(j\) in the OOB samples, recompute accuracy \(\text{Acc}_b^{(\pi_j)}\)
  3. Importance: \[ \text{MDA}(j) = \frac{1}{B} \sum_{b=1}^{B} \left( \text{Acc}_b - \text{Acc}_b^{(\pi_j)} \right) \]

This is more reliable than MDI as it uses OOB data (unseen by each tree) and is less biased by cardinality.




Permutation Importance (Model-Agnostic)

Permutation importance generalizes the Random Forest MDA idea to any model. The algorithm:

  1. Train model \(f\) on training data. Compute baseline score on the test set: \(s_0 = \text{Score}(f, X_{\text{test}}, y_{\text{test}})\)
  2. For each feature \(j = 1, \dots, p\):
    • Randomly shuffle (permute) column \(j\) in \(X_{\text{test}}\)
    • Recompute score: \(s_j = \text{Score}(f, X_{\text{test}}^{(\pi_j)}, y_{\text{test}})\)
  3. Importance of feature \(j\): \[ \text{PI}(j) = s_0 - s_j \]

A large drop in performance indicates high importance.

Advantages

Disadvantages




SHAP Values

SHAP (SHapley Additive exPlanations) is based on Shapley values from cooperative game theory. The Shapley value of feature \(j\) for observation \(i\) represents the average marginal contribution of that feature across all possible coalitions of features.

\(\phi_j^{(i)}\) = contribution of feature \(j\) to the prediction for observation \(i\).

The formula:

\[ \phi_j = \sum_{S \subseteq F \setminus \{j\}} \frac{|S|!\;(|F| - |S| - 1)!}{|F|!} \left[ f(S \cup \{j\}) - f(S) \right] \]

where \(F\) is the full feature set, \(S\) is a subset not containing \(j\), and \(f(S)\) denotes the model prediction using only features in \(S\) (with the remaining features marginalized out).

Key Properties

For global importance, aggregate across observations:

\[ \text{SHAP Importance}(j) = \frac{1}{n} \sum_{i=1}^{n} |\phi_j^{(i)}| \]




Drop-Column Importance

The most straightforward (and most computationally expensive) approach:

  1. Train the full model with all features: \(s_{\text{full}} = \text{Score}(f_{\text{all}})\)
  2. For each feature \(j\): retrain the model without feature \(j\): \(s_{-j} = \text{Score}(f_{-j})\)
  3. Importance: \[ \text{DCI}(j) = s_{\text{full}} - s_{-j} \]

Why it's the gold standard

Main drawback

Requires \(p + 1\) full model trainings. For large \(p\) or expensive models, this is often infeasible.




Caveats and Best Practices