Classical machine learning
Out-of-Bag Evaluation and Forest Interpretation
Evaluate random forests with out-of-bag predictions and interpret them through support-aware, correlation-aware methods.
By the end you can
- Explain how out-of-bag predictions are constructed and when they are insufficient
- Compare impurity, permutation, drop-column, and local importance methods
- Diagnose correlated-feature and unrealistic-perturbation failures
- Separate predictive performance, model reliance, and causal effect
Visual
Out-of-bag predictions reuse bootstrap omissions
Each training row is absent from some bootstrap samples, and it can be predicted using only the trees that did not train on it. How many rows is that? Not a vague "roughly some rows". The figure sits on Breiman and Cutler's own Random Forests page: “About one-third of the cases are left out of the bootstrap sample and not used in the construction of the kth tree.” Liaw and Wiener put the same figure at around 36% in R News in 2002. Two independent write-ups, one number.
That one-third is the whole mechanism. Bootstrap each tree and about a third of the rows are omitted from that resample. Record which examples are out of bag for that tree. Predict each row by aggregating only the trees that excluded it. Compute out-of-bag metrics from those predictions, and you have performance evidence without carving a separate internal holdout out of the training data.
Preserve a final, untouched, deployment-like test set anyway. The out-of-bag estimate is built from the same rows the forest was fitted on. The next section shows what that costs when the rows are not the independent draws the resampling assumes.
- 1
Bootstrap each tree
Roughly some training rows are omitted from each resample.
- 2
Track omitted rows
Record which examples are out of bag for that tree.
- 3
Predict with eligible trees
Aggregate only trees that excluded the row.
- 4
Compute OOB metrics
Estimate performance without a separate internal holdout.
- 5
Preserve final test
Use deployment-like untouched evidence for final claims.
OOB is valuable internal evidence, not a universal final evaluation
Out-of-bag estimates can support tree-count monitoring, feature experiments, and model comparison. What they assume is that the rows are ordinary and independent — that leaving a row out of a bootstrap sample leaves out everything that makes that row easy to predict. They become less trustworthy when groups, time, space, preprocessing leakage, repeated tuning, or nonuniform weights violate that logic.
There is a number for the gap. A random forest trained on a central-African forest inventory of 11.8 million trees reported R² = 0.53 and an RMSPE of 56.5 Mg ha⁻¹ under a random 10-fold cross-validation. The same fitted model under a spatial 44-fold cross-validation reported R² = 0.14 and an RMSPE of 77.5 Mg ha⁻¹. A null model with no predictors at all had an RMSPE of 82 Mg ha⁻¹. Ploton and colleagues published that in Nature Communications in 2020, and their abstract states the consequence plainly: “A standard nonspatial validation method suggests that the model predicts more than half of the forest biomass variation, while spatial validation methods accounting for SAC reveal quasi-null predictive power.” Row-random resampling said half the variation. Respecting the deployment boundary said the model was barely beating a model with no predictors at all.
The direction and rough size of that bias replicate. Andy Stock, choosing blocks for spatial cross-validation in a marine remote sensing case study in 2025, reports that “Depending on the model and error measure, 10-fold cross-validation underestimated prediction errors by 5% (RMSE of MBR) to 54% (APD of RFXY).”
Out-of-bag resampling is row-random by construction, so it inherits exactly this failure. Use group-aware, temporal, or spatial evaluation when those boundaries define deployment. Read the OOB number as an internal diagnostic, not as the claim you ship.
Comparison
Feature importance methods answer different questions
No importance score reveals a feature's causal contribution. Not by itself. Each of the four methods below is a different experiment on the fitted model, and three of the four have a documented failure mode with a source behind it.
Impurity importance adds split improvements attributed to each feature across trees. It is fast, it is built in, and it is a training-distribution quantity. It is also biased by the number of categories and the scale of measurement of a predictor, which Strobl and colleagues showed in 2007. Permutation importance measures score loss after disrupting one feature on a chosen evaluation set. It reflects model reliance for one metric. It can understate correlated substitutes, which Strobl and colleagues showed again in 2008. And the permutation itself can manufacture rows the model has never seen, which Hooker and colleagues showed in 2021. Drop-column comparison refits the pipeline without a feature or a group. It is expensive, it is informative, and it lets substitutes reorganize. It is the shape of experiment those same authors recommend — still not a causal intervention. Local attribution allocates one prediction among encoded features under an explanation method. Useful for case review, dependent on the background distribution, sensitive to feature dependence. It explains the fitted model, not the world.
Impurity importance
Adds split improvements attributed to each feature across trees.
- Fast and built in
- Biased toward features with many split opportunities
- Can divide credit among correlated variables
- Training-distribution quantity
Permutation importance
Measures score loss after disrupting one feature.
- Uses a chosen evaluation set
- Reflects model reliance for one metric
- Can understate correlated substitutes
- Permutation may create unrealistic rows
Drop-column comparison
Refits the pipeline without a feature or group.
- Measures retraining effect
- Expensive but informative
- Allows substitutes to reorganize
- Still not a causal intervention
Local attribution
Allocates one prediction among encoded features under an explanation method.
- Useful for case review
- Depends on background distribution
- Sensitive to feature dependence
- Explains the fitted model, not reality
Example
Correlated features can hide and redistribute importance
A forest can score 0.97 and report, on its own chart, that none of its features matter. Scikit-learn ships the demonstration as a worked example on the Breast cancer Wisconsin (diagnostic) data. A RandomForestClassifier reaches a “Baseline accuracy on test data: 0.97”. The permutation importances, computed on the training set, then report that “permuting a feature drops the accuracy by at most 0.012, which would suggest that none of the features are important”. A model scoring that well appears, by its own importance chart, to be using nothing.
The machinery behind that result has a name — two, in fact. Strobl and colleagues set them out in BMC Bioinformatics in 2008: “We identify two mechanisms responsible for this finding: (i) A preference for the selection of correlated predictors in the tree building process and (ii) an additional advantage for correlated predictor variables induced by the unconditional permutation scheme that is employed in the computation of the variable importance measure.”
- Impurity importance may split credit across whichever correlated column appears first in different trees, and Strobl and colleagues trace that to a preference for selecting correlated predictors during tree building.
- Permuting one column may cost almost nothing because its correlated substitute preserves the signal — 0.012 accuracy at most, on a forest scoring 0.97.
- Grouping the correlated columns and treating them as one concept restores the picture: scikit-learn's example clusters them hierarchically, keeps one feature per cluster, and test accuracy is still 0.97.
- Local attributions may divide or shift credit according to the explainer background and dependence assumptions, for the same reason the permutation does.
- Conclusion: report concept groups and correlation structure rather than a single ranked list, because on correlated data the ranked list can read as "nothing matters" while the model is at 0.97.
Partial dependence averages model predictions over synthetic feature changes
A partial dependence curve replaces one feature with selected values and averages predictions over other observed columns. It can summarize a global model pattern. It can also evaluate combinations that never occur. Hooker and colleagues stated the mechanism in Statistics and Computing in 2021: “In particular, we describe how breaking dependencies between features in hold-out data places undue emphasis on sparse regions of the feature space by forcing the original model to extrapolate to regions where there is little to no data.” Scikit-learn's own user guide says the same thing about the plots it draws — “in the case of correlated features, we will create absurd data points to compute the PDP/ICE”.
Individual conditional expectation curves reveal heterogeneity that the average can hide. That is not a folk observation. It is why the method exists. Goldstein and colleagues introduced ICE plots in 2015 with the reason in their abstract: “In the presence of substantial interaction effects, the partial response relationship can be heterogeneous. Thus, an average curve, such as the PDP, can obfuscate the complexity of the modeled relationship.” Scikit-learn restates it: “While the PDPs are good at showing the average effect of the target features, they can obscure a heterogeneous relationship created by interactions. When interactions are present the ICE plot will provide many more insights.”
ICE fixes the averaging problem and inherits the support problem. Both curves are drawn by substituting values into rows, so both can leave the observed data manifold, and the scikit-learn sentence above covers PDP and ICE alike. Restrict the plotted range to combinations that actually occur, or say in the caption that the curve extends past them.
Steps
Interpret a forest through converging evidence
Use several views and ask whether they tell a coherent, support-aware story. Establish held-out behavior first: metrics, calibration, slices, and support. Choose the resampling boundary that matches deployment, because the difference between R² = 0.53 and R² = 0.14 in Ploton and colleagues' forest was the boundary, not the model. Group correlated features into concepts that should be perturbed or removed together, or the chart will report 0.012 for columns the model depends on. Compare importance methods and read their disagreements as information about dependence rather than as noise. Inspect local cases: decision paths, neighbors in leaf space, attribution stability. Plot dependence curves only over plausible ranges and combinations, since breaking dependencies forces the model to extrapolate. Then test interventions separately. Do not translate predictive reliance into causal policy without evidence built for that question.
1. Establish held-out behavior
Report metrics, calibration, slices, and support before interpretation.
2. Group correlated features
Define concepts that should be perturbed or removed together.
3. Compare importance methods
Look for agreements and dependence-driven disagreements.
4. Inspect local cases
Read paths, neighbors in leaf space, and attribution stability.
5. Plot supported effects
Restrict dependence curves to plausible ranges and combinations.
6. Test interventions separately
Do not translate predictive reliance into causal policy without evidence.
Analogy
Auditing a committee by removing evidence packets
A committee's accuracy changes when one evidence packet is shuffled, withheld, or removed before retraining. Each experiment answers a different question about reliance and substitution.
Shuffling a packet can produce a case that could not exist. Two packets carrying the same evidence can each be withheld with almost no loss, while the pair together is decisive. That is what 0.97 accuracy alongside a 0.012 maximum permutation drop looks like from inside the room. None of the experiments proves the packet causes the real-world outcome.
Importance is conditional on the fitted model, the evaluation set, the perturbation, and the scoring rule.
Key idea
Importance rankings are not stable product requirements
A feature can rank highly because it proxies a mutable process, a site-specific convention, or a protected attribute. After deployment changes, the relationship may disappear while the ranking remains persuasive in an old report.
The proxy version of that failure is documented. A commercial risk algorithm affecting millions of patients was biased because it predicted health-care cost as a proxy for illness. Remedying the disparity would raise the share of Black patients receiving additional help from 17.7% to 46.5%. Obermeyer and colleagues published that in Science in 2019, and their abstract closes: “We suggest that the choice of convenient, seemingly effective proxies for ground truth can be an important source of algorithmic bias in many contexts.” The cost feature was doing real predictive work. It was also the wrong thing to be relying on.
Regulators moved the same day. On 25 October 2019 the New York State Department of Financial Services and Department of Health wrote jointly to the chief executive of UnitedHealth Group over the Impact Pro algorithm. The letter says: “We call on you to immediately investigate these reports and demonstrate that this algorithm is not racially discriminatory or to cease using Impact Pro (or any other data analytics program) if you cannot demonstrate that it does not rely on racial biases or perpetuate racially disparate impacts.”
There is also a bias that has nothing to do with the world the model was trained on. Importance moves with properties of the columns themselves. Strobl and colleagues showed it in BMC Bioinformatics in 2007: “We found that for the original random forest method the variable importance measures are affected by the number of categories and scale of measurement of the predictor variables, which are no direct indicators of the true importance of the variable.” They trace the effect to two sources: biased variable selection inside the individual classification trees, and effects induced by the bootstrap sampling with replacement itself. Their remedy is conditional inference trees with subsampling without replacement. Scikit-learn's user guide carries the warning verbatim: “impurity-based feature importance for trees is strongly biased and favor high cardinality features (typically numerical features) over low cardinality features such as binary features or categorical variables with a small number of possible categories.”
Pair importance with provenance, stability, drift, and removal tests.
A feature the model relies on is a dependency to govern, not automatically a feature to celebrate.
Position
The importance chart that costs nothing is the one that should not leave the room
Impurity importance is an attribute on the fitted object. Permutation importance is one function call against a held-out set. Those are the two cheapest of the four methods compared in this lesson, and they are the two a reader will actually meet in a report. They are also the two with a documented bias, one of them carrying the warning in its library's own manual.
Impurity-based importance moves with the number of categories a predictor happens to have, and with its scale of measurement — properties that are “no direct indicators of the true importance”. Strobl and colleagues showed that in 2007, and traced it to two mechanisms at once: the variable selection inside each tree, and the bootstrap sampling with replacement. Scikit-learn says the same thing in its own documentation: strongly biased, favoring high cardinality features. Permutation importance fails differently. Hooker and colleagues found that “PaP metrics can vastly over-emphasize correlated features in both variable importance measures and partial dependence plots”. Permuting a feature breaks its dependence with the others and pushes the model into regions where it has seen little or no data.
The alternative those authors recommend is stated in their own title — “Unrestricted Permutation forces Extrapolation: Variable Importance Requires at least One More Model, or There Is No Free Variable Importance” — and in their abstract: “measuring the change in model performance after muting the effects of the features under investigation”. That is the drop-column shape of experiment, and it costs at least one more fit. An analysis with no budget for a second fit has no budget for an importance chart either. A chart produced by a method its own documentation calls strongly biased is not something a product decision should be citing.
“There is no free variable importance” is the title of a paper, and it is a budget statement.
Forests define a learned proximity through shared leaves
Two rows can be considered similar when they land in the same leaves across many trees. That similarity has a published definition rather than an intuition. Liaw and Wiener state it in R News: “The (i, j) element of the proximity matrix produced by randomForest is the fraction of trees in which elements i and j fall in the same terminal node.” Breiman and Cutler give the arithmetic on their Random Forests page: “If two cases occupy the same terminal node, their proximity is increased by one. At the end of the run, the proximities are normalized by dividing by the number of trees.” Count shared leaves, divide by the number of trees. That is the distance.
Its own authors claim it for missing-data handling, outlier detection, and low-dimensional views of the data, and it can support diagnostics, retrieval, or anomaly analysis on that basis.
Every one of those counts comes from the forest's own splits. So the proximity inherits the forest's biases, including the split-selection bias Strobl and colleagues described. It is not an independent ground-truth distance.
A model-induced neighborhood explains similarity according to the ensemble's decisions.
A defensible forest report separates performance, reliance, and effect
Performance asks whether predictions help, and which resampling boundary was used to ask. Ploton and colleagues' forest scored R² = 0.53 or R² = 0.14 depending on that single choice. Reliance asks which inputs the fitted model uses, and that answer moves with the perturbation: the same forest can report 0.97 accuracy and a 0.012 maximum permutation drop. Effect asks what would happen if the world changed. Neither of the first two answers it.
Keep them in separate sections so an importance chart cannot silently become a policy claim. The cost of not doing so is on the record. A cost-based risk score with real predictive performance. A share of Black patients receiving additional help that a corrected target would move from 17.7% to 46.5%. A letter from two New York State regulators to the vendor's chief executive, dated 25 October 2019.
Predictive importance is not causal effect, actionability, fairness, or data quality.
Key takeaways
- About one-third of the cases are left out of each tree's bootstrap sample — around 36% by Liaw and Wiener's count — and those omitted rows are what out-of-bag prediction reuses.
- OOB evaluation is row-random by construction, so it fails where the random 10-fold cross-validation failed in Ploton and colleagues' forest: R² = 0.53 under row-random resampling against R² = 0.14 under spatial 44-fold, on the same fitted model.
- Impurity, permutation, drop-column, and local attribution answer different reliance questions, and Strobl and colleagues showed in 2007 that impurity importance moves with a predictor's number of categories and scale of measurement.
- Correlated substitutes can split or hide importance: a forest at 0.97 accuracy can show a maximum permutation drop of 0.012, and clustering the correlated columns to one per cluster still leaves accuracy at 0.97.
- Partial dependence and permutation break feature dependencies and force the model to extrapolate into sparse regions, which is why scikit-learn warns that correlated features produce absurd data points for PDP and ICE alike.
- Forest interpretation should distinguish predictive performance, fitted-model reliance, and real-world causal effect — the distinction Obermeyer and colleagues' cost proxy collapsed, at 17.7% against 46.5%.