How are predictions aggregated across trees in a Random Forest regressor?
Last updated
A Random Forest regressor predicts the arithmetic mean of the individual trees' predictions. Each tree outputs the average target value of the leaf the sample lands in, and the forest averages those outputs.
Per-tree prediction: The sample is routed down the tree to a leaf. The leaf's value is the mean of the training targets in it (with the default squared-error criterion).
Forest prediction:
The forest computes ŷ = (1/B) Σ ŷ_b over all B trees, with equal weight per tree.
In
scikit-learn,RandomForestRegressor.predictis exactly this mean.
Why averaging helps: Averaging many high-variance, low-bias trees reduces variance. The reduction is largest when trees are weakly correlated.
Consequences:
Predictions are always within the range of the training targets, so the forest cannot extrapolate.
The spread of the per-tree predictions gives a rough uncertainty signal. Quantile regression forests go further and keep the full leaf distributions to estimate quantiles instead of just the mean.
[lang:python]
import numpy as np
per_tree = np.stack([t.predict(X) for t in rf.estimators_])
assert np.allclose(per_tree.mean(axis=0), rf.predict(X))