Tutorials › Exam PA - Predictive Analytics › Conditional Permutation Importance

Exam PA · Random Forests and Ensemble Behavior · Tutorial 542 of 966

Conditional Permutation Importance

Learn to define, calculate, and interpret conditional permutation importance, including its advantages, limitations, and computational trade-offs.

Advanced 11 min read

What You'll Learn

  • Define conditional permutation importance using a fixed forest and an evaluation loss
  • Explain how conditional replacement differs from unrestricted permutation
  • Calculate importance by hand using conditional swaps and conditional resampling
  • Interpret low importance when predictors share information or are nearly determined by others
  • Identify the assumptions and computational costs of conditional sampling
  • Choose between conditional and ordinary permutation for a specified analysis

Why Preserve Predictor Dependence?

A forest can use several predictors that carry overlapping information. If one predictor is permuted across all evaluation cases, its values may become implausible in combination with the other predictors. For example, a replacement risk score that is typical of one region may be assigned to a case in a region where such scores are rare. The resulting prediction change can reflect the implausible combination as well as the forest’s reliance on the predictor.

Conditional permutation importance addresses this issue by replacing a predictor with values drawn or permuted in a way that reflects its relationship with the remaining predictors. It asks how much predictive performance changes when the predictor’s information that is not already represented by the other predictors is disrupted. The resulting quantity is a measure of a fitted model’s predictive reliance under a particular evaluation design, not a general measure of a variable’s intrinsic value.

Definition: Let \(X_j\) be the predictor being assessed, \(X_{-j}\) the vector of all other predictors, \(Y\) the outcome, and \(f\) a fixed fitted forest. Conditional permutation importance is the increase in expected evaluation loss when \(X_j\) is replaced by a draw \(\widetilde X_j\) from its conditional distribution given \(X_{-j}\). The replacement is generated independently of the original \(X_j\) and \(Y\), conditional on \(X_{-j}\). For loss function \(L\), define $$ \operatorname{CPI}_j = E\!\left[L\{Y,f(X_{-j},\widetilde X_j)\}\right] - E\!\left[L\{Y,f(X_{-j},X_j)\}\right]. $$

For regression, \(L\) is often squared error, \(L(y,\hat y)=(y-\hat y)^2\). For classification, it may be misclassification loss or a probability-based loss such as log loss. The loss and evaluation cases should be specified: an importance value has no useful interpretation apart from them.

What the Conditional Replacement Does

Ordinary permutation assigns a predictor’s observed values to cases without regard to the other predictors. Conditional permutation instead tries to preserve the relationship between \(X_j\) and \(X_{-j}\). A practical approximation might shuffle values within sufficiently similar groups of \(X_{-j}\), or use a fitted conditional distribution to generate replacements. In either case, the goal is that the replacement looks plausible given the other predictors for that case.

The conditional distribution is a substantive part of the method. If it is estimated poorly, the replacements may still be implausible or may fail to disrupt the relevant information. Grouping too coarsely can leave dependence unpreserved; grouping too finely can leave few cases to shuffle. A conditional model also adds fitting choices and computation. Thus “conditional” describes the intended replacement mechanism, not a guarantee that dependence has been captured perfectly.

1
Choose the fitted forest and evaluation cases.
Hold the fitted model fixed. For a random forest, out-of-bag (OOB) predictions can be used if the assessment is designed consistently with the forest fit; a separate validation set is another option.
2
Estimate or specify the conditional replacement mechanism.
Use a defensible way to represent \(X_j\mid X_{-j}\), such as shuffling within suitable groups or drawing from a conditional model.
3
Replace \(X_j\) and recompute predictions.
Keep every other predictor and the fitted forest unchanged. Calculate the chosen loss on the same evaluation cases.
4
Average the loss increase over replacements.
Repeat the replacement several times to reduce Monte Carlo noise, then subtract the unperturbed evaluation loss from the mean perturbed loss.

Why the Formula Measures Conditional Reliance

The replacement has the same conditional distribution as the original predictor given \(X_{-j}\), but it is generated without using the original predictor’s association with the outcome after conditioning on the other predictors. This explains both what the method preserves and what it disrupts.

Justification: By construction, \(\widetilde X_j\mid X_{-j}\) has distribution \(X_j\mid X_{-j}\). Therefore \((X_{-j},\widetilde X_j)\) has the same joint distribution as the original predictor vector \((X_{-j},X_j)\). The model is evaluated on predictor combinations that retain the modeled dependence among predictors, while the replacement does not use the original \(X_j\) or \(Y\) once \(X_{-j}\) is fixed. The first expected loss in the definition is thus the loss after conditionally disrupting the predictor’s case-specific information; the second is the loss before disruption. Their difference is the conditional permutation importance.

This argument does not imply that the difference must be positive for every fitted forest. A model can use a predictor unhelpfully, and finite evaluation samples and estimated conditional distributions introduce variation. Nor does a small value prove that the predictor has no association with the outcome: information shared with other predictors can remain available through \(X_{-j}\).

Worked Calculations

Worked Example: Conditional Swaps Within Region

A hypothetical forest predicts a numeric service-cost outcome using numeric risk score \(X\) and region \(Z\). On four evaluation cases, its fixed predictions are \(f(X,Z)=2X\). The observed costs, scores, and regions are shown below. For this hand calculation, conditional replacement means swapping the two score values within each region.

CaseRegion \(Z\)Score \(X\)Observed cost \(Y\)Original prediction
1A132
2A254
3B81716
4B91918

Method. Use mean squared error (MSE), and compare the original predictions with predictions after the within-region swaps. The original residuals \(Y-\hat Y\) are \(1,1,1,1\). Thus the original MSE is \( (1^2+1^2+1^2+1^2)/4=4/4=1\).

After swapping within region A, case 1 receives score 2 and case 2 receives score 1. Their predictions become 4 and 2. After swapping within region B, case 3 receives score 9 and case 4 receives score 8. Their predictions become 18 and 16. The new residuals are therefore \(3-4=-1\), \(5-2=3\), \(17-18=-1\), and \(19-16=3\).

The perturbed MSE is \( \{(-1)^2+3^2+(-1)^2+3^2\}/4=(1+9+1+9)/4=20/4=5\). The conditional permutation importance for this specified swap is \(5-1=4\) squared cost units. Check: the calculation preserves region-score pairings at the group level; the score is not swapped from region A into region B. The common mistake of shuffling all four scores freely would answer a different question and could create unusual score-region combinations.

Worked Example: Averaging Conditional Resamples

A hypothetical fixed regression forest has prediction function \(f(X,Z)=2X\). Two evaluation cases share the same value of the other predictor, \(Z\), so the specified conditional sampler draws a replacement score independently for each case from the empirical conditional distribution that assigns probability \(1/2\) to \(X=0\) and probability \(1/2\) to \(X=2\). The observed outcomes are \(Y_1=1\) and \(Y_2=5\), and the original scores are 0 and 2.

The original predictions are \(f(0,Z)=0\) and \(f(2,Z)=4\). The squared errors are \((1-0)^2=1\) and \((5-4)^2=1\), giving original MSE \((1+1)/2=1\).

For case 1, a replacement score of 0 gives prediction 0 and squared error \((1-0)^2=1\); a replacement score of 2 gives prediction 4 and squared error \((1-4)^2=9\). Its expected perturbed squared error is \((1+9)/2=5\). For case 2, the corresponding squared errors are \((5-0)^2=25\) and \((5-4)^2=1\), so its expected perturbed squared error is \((25+1)/2=13\).

The expected perturbed MSE is \((5+13)/2=9\), and the sampler-based conditional importance is \(9-1=8\) squared outcome units. Check: this answer averages over independent conditional draws with replacement. A forced swap without replacement would always exchange the two scores and produce a different estimate. The replacement scheme must therefore be stated when reporting a hand-calculated value.

Worked Example: A Predictor Determined by the Other Predictor

In a hypothetical claims dataset, a forest predicts a numeric claim amount using a binary territory indicator \(Z\) and numeric score \(X\). In the evaluation sample, both cases in territory A have \(X=1\), both cases in territory B have \(X=9\), and the observed claim amounts are \(2,2,18,18\), respectively. The fixed forest predicts \(f(X,Z)=2X\).

The original predictions are \(2,2,18,18\), so every residual is zero and the original MSE is 0. Under the specified conditional mechanism, replacements are drawn from the observed score distribution within territory. Given A, the only available score is 1; given B, the only available score is 9. Every replacement therefore leaves every prediction unchanged. The perturbed MSE is also 0, and the estimated conditional importance is \(0-0=0\).

This result does not show that the fitted forest ignores \(X\): its prediction function explicitly uses \(X\). It shows that this evaluation sample supplies no variation in \(X\) beyond territory, so the conditional replacement cannot isolate any additional information in \(X\). Common mistake avoided: interpreting zero conditional importance as proof of no predictive association. The predictor may be a useful proxy, but its information is redundant with \(Z\) in this example.

When the Extra Work Is Worthwhile

Conditional permutation is most useful when predictor dependence is substantial and unrestricted shuffling would create combinations poorly represented in the data. It can clarify whether a predictor contributes information beyond correlated alternatives, rather than measuring how badly the forest performs when that predictor is replaced by arbitrary values.

That distinction changes the interpretation. A predictor with high ordinary permutation importance but low conditional importance may be a strong proxy for information carried by other predictors. A low conditional importance can also arise because the predictor has little variation once the others are known, as in the preceding example. Neither result by itself establishes a causal effect or the value of collecting the predictor in a different population.

Conditional estimation is more demanding than ordinary permutation. It requires a credible conditional distribution or a defensible grouping scheme, and repeated replacements can require many prediction evaluations. In high-dimensional settings, finding cases that are genuinely comparable on all other predictors can be difficult. If the conditional model is misspecified, the importance estimate can reflect errors in that model as well as forest behavior.

Use the method when predictor dependence makes unrestricted permutation hard to interpret and when the data support a reasonable conditional replacement strategy. If dependence is weak, the ordinary permutation may be adequate and easier to explain. In either case, report the evaluation data, loss function, replacement procedure, and whether the value is averaged over repeated permutations. Conditional permutation importance is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Common Exam Traps

  • Calling any shuffle conditional. A global shuffle does not preserve the relationship with the other predictors. State what is conditioned on and how replacements are generated.
  • Comparing unlike losses. Importance values calculated with different loss functions, evaluation sets, or outcome scales are not directly comparable.
  • Assuming importance must be positive. The estimate is a difference in losses for a fixed model and can be negative because of sampling variation or harmful model reliance.
  • Equating low conditional importance with no association. A predictor’s information may be redundant with other predictors, or the evaluation sample may contain little conditional variation.
  • Ignoring the sampler. Shuffling within groups, drawing independently with replacement, and forced swaps without replacement need not produce the same finite-sample estimate.

Check Your Understanding

For each problem, identify the loss and replacement scheme before interpreting the result.

  1. A fixed forest has three numeric-outcome predictions \(2,4,8\) for observed values \(3,3,10\). After a specified conditional replacement, its predictions are \(3,5,7\). Calculate the original MSE, the perturbed MSE, and the conditional importance for this replacement. (Answer: Original MSE \(= (1+1+4)/3=2\); perturbed MSE \(=(0+4+9)/3=13/3\); importance \(=7/3\).)
  2. Within a conditional group, a score is equally likely to be 1 or 3, and the forest predicts \(f(X)=X\). For one case with outcome \(Y=2\), calculate its expected squared loss after replacement. (Answer: \(\{(2-1)^2+(2-3)^2\}/2=1\).)
  3. A predictor has ordinary permutation importance 12 and conditional permutation importance 1 under the same evaluation loss. Give a plausible interpretation that does not claim the predictor is useless. (Answer: Much of its predictive information may be shared with other predictors; conditional importance measures the smaller additional reliance under the stated replacement scheme.)
  4. In a validation set, \(X\) is constant within every stratum of \(Z\). A forest’s prediction changes with \(X\). What happens to within-stratum conditional permutation importance, and what does that result mean? (Answer: It is zero if replacements cannot change \(X\); the validation data provide no within-stratum variation to measure information in \(X\) beyond \(Z\), not proof that the forest does not use \(X\).)
  5. For a binary classifier, the original mean misclassification loss is \(0.15\). Averaging 20 conditional replacements gives mean loss \(0.22\). Calculate the estimated importance and state its units. (Answer: \(0.22-0.15=0.07\), an increase of 0.07 in misclassification proportion, or 7 percentage points.)
Clinical Biostats