Explainable Random Forest

Machine Learning
Introduced by
Breiman, L. (RF); Lundberg & Lee (SHAP attribution)
Year
2001–2017
Type
Interpretable ensemble (bagging + post-hoc attribution)
Family
Machine learning

What does it do?

Explainable Random Forest (XRF) is a workflow rather than a new algorithm.

A standard Random Forest is trained, and post-hoc attribution methods, principally SHAP values and mean decrease in impurity (MDI), are then applied to the fitted ensemble to explain its predictions. Predictive accuracy is identical to that of the underlying forest, and the explanations describe the model's behaviour, not the data-generating process.

The intuition behind the method

A standard Random Forest is a set of decision trees whose votes are combined. It is usually accurate but hard to inspect. Explainable Random Forest adds two kinds of explanation. Globally, it ranks which features the ensemble relies on most across the dataset. Locally, it shows how each feature moved a single prediction away from the baseline. SHAP values, which come from cooperative game theory, split that gap into additive per-feature shares, much as a shared cost might be divided among contributors. Together these views make the model's reasoning easier to review without retraining it.

History

The Random Forest ensemble was introduced by Breiman (2001). SHAP, the attribution method most often used in XRF workflows, was presented as a unified framework for interpreting model predictions by Lundberg and Lee (2017). Tree-specific algorithms for computing SHAP values on tree ensembles have since been developed. "Explainable Random Forest" is best understood as a common workflow combining these elements rather than a single named method with its own originator.

When to use it

Use Explainable Random Forest when you need both competitive predictive performance and feature-level explanations on tabular data, for example in clinical risk scoring, credit assessment or social-science research where results must be justified feature by feature. It is well suited to settings where transparency of model behaviour is required for review. Avoid it when the sample is very small, because both the forest and its SHAP values become unstable. Also avoid it when a linear model with explicit coefficients is adequate, or when the audience needs a white-box model that can be computed by hand, since XRF explains a complex ensemble after the fact rather than replacing it.

Limitations and considerations

  • SHAP values explain the model, not necessarily the true data-generating process; a high SHAP value does not establish a causal effect.
  • Computational cost of exact tree SHAP grows with the number of trees, the depth of the trees and the number of features, so very large forests on wide datasets can be slow.
  • MDI importance is biased toward features with many distinct values, so it can overstate continuous or high-cardinality categorical predictors.
  • Explanations inherit the instability of the forest, so they can change substantially on small datasets where the forest itself varies from one fit to another.
  • SHAP values depend on how absent features are represented, for example through a background dataset or through the tree's own path statistics. When features are correlated, these conventions can give different attributions, so results should be rechecked under a second convention and the choice reported.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Keeps the predictive behaviour of the underlying Random Forest, because attribution is applied after training and does not change the fitted trees.
  • Provides both global (dataset-level) rankings and local (observation-level) contributions, which address different review questions.
  • Tree-specific algorithms (TreeSHAP-style) compute Shapley values for tree ensembles without sampling approximation, exact with respect to the chosen convention for absent features.
  • Makes no parametric assumption about how features relate to the outcome, so it can represent nonlinear effects and interactions.
  • Out-of-bag error gives an internal estimate of predictive error without a separate hold-out set.

Applications

  • Clinical risk scoring and patient stratification, where per-patient feature contributions can be reviewed.
  • Credit risk and loan approval models that require feature-level explanations of decisions.
  • Social-science and policy research in which feature effects are reported alongside predictive accuracy.
  • Environmental and ecological modelling that needs both predictions and variable importance.
  • Model debugging, and as one input to fairness review by comparing SHAP value distributions across demographic groups. Such comparisons can flag where to investigate, but differences in attribution do not on their own establish unfair treatment or identify its source, since they may reflect correlated proxies or differing base rates.

How it works

How it works

1

A standard Random Forest is trained on bootstrap samples, with a random subset of features considered at each split, producing an ensemble of decorrelated trees. Training is identical to the vanilla Random Forest; the explainability layer is applied to the fitted ensemble without retraining.

2

Mean Decrease in Impurity (MDI) sums, over all trees and all splits that use feature j, the weighted reduction in node impurity (Gini or variance). The result is a global ranking of predictors based on the training structure of the forest. Because it is computed from impurity reductions during training, it reflects how the trees were built rather than how the trained model responds to changes in each feature.

Formula
\text{MDI}_j = \sum_{t}\sum_{s\in S_j^t} p(s)\,\Delta i(s)
3

SHAP (SHapley Additive exPlanations) assigns each feature a Shapley value for each prediction, equal to the feature's average marginal contribution across all orderings in which features can be added. Evaluating f_S(x) for a subset S requires a convention for how features outside S are represented, so the attribution depends on that convention. For tree ensembles, Shapley values can be computed with a tree-specific algorithm (TreeSHAP) that avoids enumerating all feature subsets, which makes the calculation practical for large forests. The values are exact with respect to the convention chosen, and different conventions can give different attributions when features are correlated.

Formula
\phi_i = \sum_{S\subseteq F\setminus\{i\}} \frac{|S|!(|F|-|S|-1)!}{|F|!}[f_{S\cup\{i\}}(x)-f_S(x)]
4

For a single observation, SHAP values decompose the prediction into the baseline plus a signed contribution from each feature. Waterfall and force plots show which features pushed the prediction up or down for that case, which can support case review and model debugging. These plots describe the model's attribution for that input, not what would happen if the input were changed in the real world.

5

Predictive performance is assessed separately, using out-of-bag error or cross-validation, so that the explained model is also shown to be accurate. Explanations can be checked for plausibility by perturbing features, for example by permuting a feature's values, and observing whether predictions change in line with the attributions. Such checks are diagnostic and do not guarantee that an attribution is correct.

Common pitfalls

  • Conflating SHAP importance with causal importance. When features are correlated, SHAP distributes shared credit among them in ways that need not match causal structure.
  • Reporting only MDI rankings. MDI can inflate the importance of continuous or high-cardinality categorical features, so a SHAP-based or permutation-based ranking should be reported alongside it.
  • Skipping predictive validation (cross-validation, AUC, F1) and presenting only explanation outputs as evidence that the model is good.
  • Summarising SHAP values without checking whether the forest is overfitting, which produces tidy explanations of a flawed model.
  • Treating local SHAP waterfall plots as counterfactuals, that is, as statements about what would change the outcome if an input were altered.

Frequently asked questions

Is Explainable Random Forest a separate algorithm or a workflow?

It is a workflow: a standard Random Forest is trained and then attribution methods are applied to interpret it. SHAP is the principal post-hoc method. MDI is computed from the impurity reductions recorded during training, so it reflects the forest's structure rather than a separate post-hoc step. No retraining or architectural change to the forest is required.

Does adding explainability reduce predictive accuracy?

No. Explainability methods are applied after training and do not alter the model's parameters or predictions. The accuracy of an Explainable Random Forest is identical to that of the underlying forest.

What is the difference between MDI and SHAP importance?

MDI (Mean Decrease in Impurity) is computed during training by summing weighted impurity reductions over all splits involving a feature; it is fast but biased toward features with many distinct values. SHAP values are computed after training and are grounded in the Shapley axioms, which reduces some of the problems of MDI, but SHAP can still be misleading when features are strongly correlated, and it requires additional computation.

Can SHAP values be used for causal inference?

Not directly. SHAP values measure each feature's contribution to the model's prediction, not its causal effect on the outcome. In the presence of correlated features, SHAP distributes shared credit across correlated predictors in ways that do not correspond to causal mechanisms.

What sample size is needed for reliable SHAP estimates?

There is no single threshold. The reliability of SHAP values is bounded by the reliability of the underlying forest, and with very small samples both the forest and its explanations become unstable and should be interpreted with caution.

Related methods

Sources

  1. Lundberg, S. M., & Lee, S.-I. (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems, 30, 4765–4774.

    Open publication reference
  2. Breiman, L. (2001). Random Forests. Machine Learning, 45, 5–32.

    Open DOI reference