Tutorials › Statistical Learning (Graduate) › Tree Weights and Their Normalization Identities

Randomized Forests and Consistency · Tutorial 841 of 989

Tree Weights and Their Normalization Identities

Learn to express a randomized forest prediction through data-dependent weights and verify what those weights imply—and what they do not.

Advanced 11 min read

What You'll Learn

  • Write a regression-tree leaf prediction as a weighted sum of training responses.
  • Derive nonnegativity and unit-sum identities for tree and forest weights.
  • Determine which training observations can receive positive weight at a query.
  • Exchange a finite weighted sum and conditional expectation over tree randomization.
  • Distinguish algebraic weight identities from claims requiring independence from responses.
  • Check forest predictions numerically using tree-specific and averaged weights.

Why Write a Forest as Weights?

A regression tree predicts at a query point by averaging responses from training observations that fall in the same terminal leaf. A forest averages predictions from randomized trees. Expressing these operations in terms of weights makes the connection explicit: each training response contributes to the prediction with a nonnegative coefficient, and those coefficients add to one. The resulting identities are useful for interpreting a prediction and checking a calculation.

The weights are generally data-dependent. In particular, if the tree-building procedure chooses splits using the responses, the weights can depend on the observed responses as well as on the predictors. The identities below are algebraic and remain true in that setting; they do not, by themselves, make the weights independent of the responses.

Tree and Forest Weights

Fix a training data set \(D=((X_1,Y_1),\ldots,(X_n,Y_n))\) and a query point \(x\). Let \(\Theta\) denote all randomness used to construct one tree, such as randomized feature selection or a random training sample. Once \(D\) and \(\Theta\) are fixed, the tree has a terminal leaf containing \(x\). Denote that leaf by \(L(x;D,\Theta)\).

For a tree that averages the training responses represented in each leaf, let \(M_i(\Theta)\) be the number of times observation \(i\) is represented in the tree’s training sample. For an ordinary unweighted tree fit on the full sample, \(M_i=1\). For a bootstrap tree, \(M_i\) is the bootstrap multiplicity. The leaf prediction is defined only when the leaf has positive total represented sample size.

Definition: The tree weight assigned to observation \(i\) at \(x\) is $$ W_i(x;D,\Theta)= \frac{M_i(\Theta)\,\mathbf{1}\{X_i\in L(x;D,\Theta)\}} {\sum_{j=1}^n M_j(\Theta)\,\mathbf{1}\{X_j\in L(x;D,\Theta)\}}. $$ The tree prediction is \(T(x;D,\Theta)=\sum_{i=1}^n W_i(x;D,\Theta)Y_i\). The randomized forest prediction, averaging over the tree-building randomness conditional on \(D\), is $$ m_D(x)=E_\Theta[T(x;D,\Theta)\mid D,x]. $$ The corresponding forest weight is \(\alpha_i(x;D)=E_\Theta[W_i(x;D,\Theta)\mid D,x]\).

The indicator in the numerator is one exactly when training observation \(i\) is assigned to the same terminal leaf as the query. Thus a tree gives zero weight to observations outside that leaf and to observations with zero multiplicity in its training sample. A forest can give positive weight to an observation if there is positive probability that a randomized tree assigns it positive weight.

Worked Example: Weights in a Bootstrap Leaf

Suppose a tree’s leaf containing \(x\) contains observations 1, 2, and 4 from the original training data. Their bootstrap multiplicities are \(M_1=2\), \(M_2=1\), and \(M_4=3\); observation 3 is not in this leaf. The responses are \(Y_1=10\), \(Y_2=16\), \(Y_3=100\), and \(Y_4=14\). Find the tree weights and prediction.

The total multiplicity in the leaf is \(2+1+3=6\). Therefore, $$ W_1=\frac{2}{6}=\frac13,\qquad W_2=\frac{1}{6},\qquad W_3=0,\qquad W_4=\frac{3}{6}=\frac12. $$ The weights are nonnegative and sum to \(1/3+1/6+0+1/2=1\). The prediction is $$ T(x)=\frac13(10)+\frac16(16)+0(100)+\frac12(14) =\frac{10}{3}+\frac{8}{3}+7=13. $$ The response \(Y_3=100\) has no effect because observation 3 is outside the query’s leaf.

Tree-Weight Identities

The main properties follow directly from the definition, provided the leaf contains at least one represented training observation. No assumption that the tree partition was chosen independently of the responses is needed for these pointwise identities.

Theorem: For every fixed \(D,\Theta,x\) for which the query leaf has positive represented sample size, the tree weights satisfy $$ W_i(x;D,\Theta)\geq 0,\qquad \sum_{i=1}^n W_i(x;D,\Theta)=1. $$ Moreover, \(W_i(x;D,\Theta)>0\) only if \(M_i(\Theta)>0\) and \(X_i\in L(x;D,\Theta)\). Consequently, \(T(x;D,\Theta)\) is a convex combination of the responses represented in the query leaf.

Proof. Each multiplicity \(M_i(\Theta)\) is nonnegative, and the indicator is either zero or one. The denominator is positive by assumption. Hence every weight is nonnegative. Summing the numerators over \(i\) gives exactly the denominator: $$ \sum_{i=1}^n W_i(x;D,\Theta) = \frac{\sum_{i=1}^n M_i(\Theta)\mathbf{1}\{X_i\in L(x;D,\Theta)\}} {\sum_{j=1}^n M_j(\Theta)\mathbf{1}\{X_j\in L(x;D,\Theta)\}} =1. $$ The numerator for observation \(i\) is zero if its multiplicity is zero or it is not in the query leaf. Finally, a weighted sum with nonnegative weights summing to one is a convex combination. In particular, the tree prediction lies between the smallest and largest responses with positive tree weight. \(\square\)

For an unweighted tree fit on the full sample, this formula reduces to equal weights among the observations in the query leaf. If that leaf contains \(k\) training observations, each receives weight \(1/k\). Bootstrap multiplicities instead give repeated observations proportionally more weight.

Worked Example: Equal Weights in an Unweighted Leaf

An unweighted tree is fit on five training observations. The query \(x\) and observations 1, 3, and 5 lie in the same terminal leaf; observations 2 and 4 do not. Their responses are \(Y_1=2\), \(Y_2=7\), \(Y_3=5\), \(Y_4=9\), and \(Y_5=8\). The leaf contains three training observations, so each has weight \(1/3\), while the other two have weight zero.

Thus \(T(x)=(2+5+8)/3=5\). The result is between the smallest and largest responses in the leaf, 2 and 8. The responses 7 and 9 are irrelevant to this tree prediction because their observations do not share the query’s leaf.

Forest Weights and Conditional Expectations

Averaging over tree randomness preserves the same basic properties, provided the query leaf has positive represented sample size almost surely under the tree randomization. Conditional expectations here are taken over \(\Theta\), with \(D\) and \(x\) fixed. Since \(n\) is finite and each weight lies between zero and one, the expectations exist and can be interchanged with the finite sum.

Theorem: For the forest weights \(\alpha_i(x;D)=E_\Theta[W_i(x;D,\Theta)\mid D,x]\), $$ \alpha_i(x;D)\geq 0,\qquad \sum_{i=1}^n\alpha_i(x;D)=1, $$ and $$ m_D(x)=\sum_{i=1}^n\alpha_i(x;D)Y_i. $$ If a tree can give observation \(i\) positive weight only when a specified support condition holds, then \(\alpha_i(x;D)=0\) whenever that condition has probability zero under the tree randomization.

Proof. Conditional expectation preserves nonnegativity, so \(\alpha_i\geq0\). By linearity of conditional expectation and the tree unit-sum identity, $$ \sum_{i=1}^n\alpha_i =\sum_{i=1}^n E_\Theta[W_i\mid D,x] =E_\Theta\!\left[\sum_{i=1}^n W_i\mid D,x\right] =E_\Theta[1\mid D,x]=1. $$ For the prediction identity, each \(Y_i\) is fixed when conditioning on the full data \(D\). Therefore, $$ m_D(x) =E_\Theta\!\left[\sum_{i=1}^n W_iY_i\mid D,x\right] =\sum_{i=1}^n E_\Theta[W_i\mid D,x]Y_i =\sum_{i=1}^n\alpha_iY_i. $$ If a weight is zero except on an event of probability zero, its conditional expectation is zero. This proves the support assertion. \(\square\)

It follows that \(m_D(x)\) also lies between the smallest and largest training responses with positive forest weight. The forest weights need not be equal: they record how often, and with what tree-specific weight, each observation contributes across the randomized trees.

Worked Example: Averaging Randomized Tree Weights

There are two training responses, \(Y_1=0\) and \(Y_2=1\). A randomized tree has two possible outcomes, each with probability \(1/2\). In outcome A its weights are \((1,0)\); in outcome B they are \((1/2,1/2)\). Calculate the expected weights and the randomized forest prediction.

The first forest weight is $$ \alpha_1=E[W_1]=\frac12(1)+\frac12\left(\frac12\right)=\frac34. $$ The second is $$ \alpha_2=E[W_2]=\frac12(0)+\frac12\left(\frac12\right)=\frac14. $$ They are nonnegative and sum to one. The prediction in outcome A is \(1(0)+0(1)=0\); in outcome B it is \((1/2)(0)+(1/2)(1)=1/2\). Averaging the two tree predictions gives $$ m_D(x)=\frac12(0)+\frac12\left(\frac12\right)=\frac14. $$ The weight representation gives the same answer: $$ \alpha_1Y_1+\alpha_2Y_2=\frac34(0)+\frac14(1)=\frac14. $$ In particular, the expected prediction is \(1/4\), not \(1/2\): only one of the two equally likely tree outcomes predicts \(1/2\), and the other predicts zero.

Finite Forests and Support

A practical forest contains a finite number \(B\) of trees. Write their weights and predictions as \(W_i^{(b)}(x)\) and \(T^{(b)}(x)\), for \(b=1,\ldots,B\). The finite-forest weight is the average of the tree weights: $$ \widehat{\alpha}_{i,B}(x)=\frac{1}{B}\sum_{b=1}^B W_i^{(b)}(x). $$ Then, simply by rearranging finite sums, the forest prediction is $$ \widehat{m}_B(x)=\frac{1}{B}\sum_{b=1}^B T^{(b)}(x) =\sum_{i=1}^n\widehat{\alpha}_{i,B}(x)Y_i. $$ Each finite-forest weight is nonnegative, and the weights sum to one because each tree’s weights do. If each tree has the same conditional marginal distribution, given \(D,x\), as the single randomized tree used to define \(\alpha_i(x;D)\), then the expected finite-forest weights equal \(\alpha_i(x;D)\), whether or not the trees are independent: linearity of expectation gives \(E[\widehat{\alpha}_{i,B}\mid D,x]=\alpha_i\).

Support can be stated at two levels. For one tree, positive weight requires membership in the query leaf and positive multiplicity. For the forest, positive weight requires positive probability of positive tree weight. For a finite forest, it requires positive weight in at least one of the realized trees. Consequently, averaging cannot assign weight to an observation that receives zero weight in every component tree.

Worked Example: Checking Finite-Forest Support

Suppose three realized trees give weights for four observations as follows: $$ (1/2,1/2,0,0),\qquad (0,1/3,2/3,0),\qquad (0,0,0,1). $$ The finite-forest weights are their componentwise averages: $$ \widehat{\alpha}_{1,3}=\frac{1/2}{3}=\frac16,\quad \widehat{\alpha}_{2,3}=\frac{1/2+1/3}{3}=\frac{5}{18},\quad \widehat{\alpha}_{3,3}=\frac{2/3}{3}=\frac29,\quad \widehat{\alpha}_{4,3}=\frac13. $$ Their sum is \(3/18+5/18+4/18+6/18=1\). All four observations receive positive finite-forest weight because each appears with positive weight in at least one tree. If observation 4 had received zero weight in every tree, its averaged weight would also be zero.

What the Identities Do Not Say

A common mistake is to infer that because the weights are nonnegative and sum to one, they are independent of the responses. That conclusion does not follow. A tree can select splits using the observed \(Y_i\), and those splits determine which observations share a leaf. In that case the weights themselves can change when the responses change. The equality \(m_D(x)=\sum_i\alpha_iY_i\) is still valid: it averages tree-specific weighted predictions with the weights calculated from the same data.

For the same reason, one cannot generally take an expectation over the responses by treating the weights as fixed. An expression such as \(E[\alpha_iY_i\mid X_1,\ldots,X_n]=\alpha_i E[Y_i\mid X_1,\ldots,X_n]\) is valid if \(\alpha_i\) is measurable given the conditioning variables. If \(\alpha_i\) and \(Y_i\) are conditionally independent given \(X_1,\ldots,X_n\), the valid factorization is \(E[\alpha_iY_i\mid X_1,\ldots,X_n]=E[\alpha_i\mid X_1,\ldots,X_n]E[Y_i\mid X_1,\ldots,X_n]\); more generally, this factorization holds when their conditional covariance is zero. The nonnegativity, unit-sum, support, and conditional-expectation identities established here require no such independence assumption; stronger response-conditional claims do.

Key takeaway: A regression forest prediction is a weighted average of the training responses. Tree weights are normalized leaf multiplicities; forest weights are their conditional averages. Their nonnegativity, unit sum, and support follow from the construction, but none of these facts alone imply that the weights are independent of the responses.

Check Your Understanding

Use the definitions and identities above to answer the following.

  1. A query leaf contains observations with multiplicities 1, 2, and 5. What are their tree weights, and why do they sum to one?
  2. If an observation has zero weight in every realized tree in a finite forest, what is its finite-forest weight?
  3. Explain why averaging tree weights preserves nonnegativity and the unit-sum property.
  4. In the randomized two-tree-outcome example, recompute the forest prediction if the responses are \(Y_1=4\) and \(Y_2=12\), keeping the same weights and probabilities.
  5. Why does the weighted-average identity not establish that forest weights are independent of the training responses?
Clinical Biostats