Tutorials › Statistical Learning (Graduate) › Forest Weights as Adaptive Kernels

Randomized Forests and Consistency · Tutorial 856 of 989

Forest Weights as Adaptive Kernels

Learn to read forest weights as a local probability distribution, quantify their concentration and effective support, and identify when a weighted-variance formula is justified.

Advanced 10 min read

What You'll Learn

  • Express a forest prediction as integration against a data-adaptive discrete probability measure.
  • Distinguish forest weights from a fixed, translation-invariant kernel.
  • Relate weight outside a neighborhood to the error in local averaging.
  • Calculate effective support and interpret its limits.
  • State the conditional assumptions needed for a weighted-noise variance identity.

Forest Predictions as Local Averages

A regression forest prediction at a query point \(x\) is a weighted average of training responses. The weights encode how the collection of trees places \(x\) and the training predictors into terminal leaves. This perspective connects forest prediction to kernel smoothing, but with an important distinction: the forest’s weights are learned from the data and depend on the query point. They are not generally evaluations of one fixed function of the distance between \(x\) and \(X_i\).

The useful question is therefore not whether a forest is literally a classical kernel estimator. It is how its weights distribute mass over the observed predictors. If most weight falls near \(x\), the prediction behaves like a local average. If substantial weight remains far away, the prediction may mix responses from regions where the regression function differs from its value at \(x\).

Definition: For a sample of predictors \(X_1,\ldots,X_n\), forest weights at \(x\) are numbers \(W_{ni}(x)\), \(i=1,\ldots,n\), satisfying \(W_{ni}(x)\geq 0\) and \(\sum_{i=1}^n W_{ni}(x)=1\). The corresponding prediction is \(\hat m_n(x)=\sum_{i=1}^n W_{ni}(x)Y_i\). The weights define a data-adaptive discrete probability measure \(\hat P_{n,x}=\sum_{i=1}^n W_{ni}(x)\delta_{X_i}\), so that \(\hat m_n(x)\) is the weighted average of the observed responses under that measure.

For example, a tree that predicts by averaging the responses in the leaf containing \(x\) assigns equal weight to observations in that leaf and zero weight to observations outside it. A forest averages such tree weights across trees. Thus a forest weight can be positive even when \(X_i\) is not in the same leaf as \(x\) in every tree. The resulting weights summarize the forest’s aggregate notion of which observations are relevant to \(x\).

From Leaf Membership to Adaptive Weights

Suppose tree \(b\) has a terminal leaf \(L_b(x)\) containing \(x\), and let \(N_b(x)\) be the number of training predictors in that leaf. If the tree predicts by the within-leaf response average, its weight on observation \(i\) is \(\mathbf{1}\{X_i\in L_b(x)\}/N_b(x)\), provided \(N_b(x)>0\). Averaging over \(B\) trees gives

$$ W_{ni}(x)=\frac{1}{B}\sum_{b=1}^B \frac{\mathbf{1}\{X_i\in L_b(x)\}}{N_b(x)}. $$

Each tree’s weights are nonnegative and sum to one, so their average also has those properties. More generally, the interpretation applies whenever the forest’s prediction has nonnegative normalized weights, including suitable randomized or subsampled constructions. The weights can depend on the training predictors, the tree randomization, and—in response-adaptive procedures—possibly the responses as well.

A classical kernel estimator typically uses a fixed kernel shape and a bandwidth to assign weight according to a scaled distance from \(x\), followed by normalization. Forest weights instead arise from a collection of data-adaptive partitions. The word kernel here describes the role of the weights as a localized averaging rule; it does not imply that the forest uses a fixed radial kernel, or that its weights depend only on pairwise distances.

Worked Example: Averaging Three Tree Weight Vectors

At query \(x\), suppose three trees place the query in leaves containing training indices \(\{1,2\}\), \(\{2,3,4\}\), and \(\{1,4\}\), respectively. Each tree averages responses within its leaf. Find the forest weights.

The first tree assigns weights \((1/2,1/2,0,0)\). The second assigns \((0,1/3,1/3,1/3)\). The third assigns \((1/2,0,0,1/2)\). Averaging coordinates across the three trees gives

$$ (W_{n1},W_{n2},W_{n3},W_{n4}) =\left(\frac13,\frac{5}{18},\frac19,\frac{5}{18}\right). $$

For instance, the weight on observation 2 is \(\{1/2+1/3+0\}/3=5/18\). The weights are nonnegative and sum to \((6+5+2+5)/18=1\). They record aggregate leaf co-membership, not just the membership of one particular tree.

Neighborhood Mass and Local Averaging

Choose a metric \(d\) on the predictor space. For radius \(r>0\), define the forest’s mass within the neighborhood of \(x\) by \(A_{n,r}(x)=\sum_{i=1}^n W_{ni}(x)\mathbf{1}\{d(X_i,x)\leq r\}\). Since the weights sum to one, \(1-A_{n,r}(x)\) is the weight outside that neighborhood. This quantity gives a direct measure of localization at the chosen radius.

Result: Suppose \(m\) is bounded by \(|m(z)|\leq M\) on the predictor space and has modulus of continuity \(\omega\), meaning \(|m(z)-m(x)|\leq\omega(r)\) whenever \(d(z,x)\leq r\), where \(\omega(r)\to0\) as \(r\downarrow0\). For any nonnegative normalized weights, \[ \left|\sum_{i=1}^n W_{ni}(x)m(X_i)-m(x)\right| \leq \omega(r)A_{n,r}(x)+2M\{1-A_{n,r}(x)\}. \]

Proof. Subtract \(m(x)\) from the weighted average and use that the weights sum to one: \(\sum_i W_{ni}(x)m(X_i)-m(x)=\sum_i W_{ni}(x)\{m(X_i)-m(x)\}\). Apply the triangle inequality and split the sum into indices with \(d(X_i,x)\leq r\) and those with \(d(X_i,x)>r\). For the first set, the absolute difference is at most \(\omega(r)\); its total weight is \(A_{n,r}(x)\). For the second set, boundedness gives \(|m(X_i)-m(x)|\leq |m(X_i)|+|m(x)|\leq2M\); its total weight is \(1-A_{n,r}(x)\). Adding the two bounds proves the inequality. \(\square\)

The result separates two sources of error in the weighted signal average. Weight placed near \(x\) incurs at most the local variation \(\omega(r)\), while weight placed farther away is controlled only by the global bound \(2M\). In particular, if radii \(r_n\) shrink to zero and \(1-A_{n,r_n}(x)\) tends to zero, then both terms tend to zero: \(\omega(r_n)\to0\), and the outside mass vanishes. This is a deterministic implication for any realized set of weights and predictors; probabilistic claims require showing that the mass condition holds in the relevant mode of convergence.

Worked Example: Bounding the Signal Averaging Error

Suppose \(|m(z)|\leq 2\), and \(m\) is 1-Lipschitz: \(|m(z)-m(x)|\leq d(z,x)\). At a particular query, let \(r=0.2\) and suppose the weights put mass \(0.8\) within distance \(0.2\). Use the result to bound the difference between the weighted signal average and \(m(x)\).

Here \(M=2\), \(\omega(0.2)=0.2\), and \(A_{n,0.2}(x)=0.8\). Therefore

$$ \left|\sum_i W_{ni}(x)m(X_i)-m(x)\right| \leq (0.2)(0.8)+2(2)(0.2) =0.16+0.8=0.96. $$

This is a valid worst-case bound, not a claim that the actual error equals \(0.96\). The outside mass is only known to be \(0.2\); without more information about the distant predictors or the shape of \(m\), their contribution can be as large as the bound allows.

Effective Support: How Concentrated Are the Weights?

Neighborhood mass measures localization relative to a chosen radius. A different summary measures concentration without choosing a radius: the effective support, also called the effective sample size of the weights, is the reciprocal of the sum of their squares.

Definition: For nonnegative normalized weights, define \(N_{\mathrm{eff}}(x)=1/\sum_{i=1}^n W_{ni}(x)^2\). It equals the number of equally weighted observations that would have the same sum of squared weights. It is a weight-concentration summary, not necessarily the number of distinct observations used by the forest.

If exactly \(k\) observations have positive weight, then \(1\leq N_{\mathrm{eff}}(x)\leq k\). To verify this, nonnegativity and normalization imply \(\sum_i W_{ni}(x)^2\leq(\sum_i W_{ni}(x))^2=1\), so the effective support is at least one. For the other direction, apply Cauchy–Schwarz to the \(k\) positive weights: \(1=(\sum_i W_{ni}(x))^2\leq k\sum_i W_{ni}(x)^2\). Taking reciprocals yields \(N_{\mathrm{eff}}(x)\leq k\). Equality at the upper bound occurs when those \(k\) weights are equal. Thus a large effective support requires weight to be spread out, but it does not by itself show that the observations receiving weight are close to \(x\).

Worked Example: Computing Effective Support

For the weights from the three-tree example, \((1/3,5/18,1/9,5/18)\), compute the effective support and compare it with the number of positive weights.

First square each weight and add:

$$ \sum_{i=1}^4 W_{ni}(x)^2 =\frac19+\frac{25}{324}+\frac1{81}+\frac{25}{324} =\frac{36+25+4+25}{324} =\frac{90}{324} =\frac5{18}. $$

Consequently \(N_{\mathrm{eff}}(x)=18/5=3.6\). All four observations have positive weight, so the effective support is below four, as expected for unequal weights. It need not be an integer: it is an equivalent-support summary, not a literal count.

When Effective Support Gives a Variance Formula

Effective support is often linked to the noise variance of a weighted average. That link requires care: if the weights use the responses, conditioning on the weights can change the conditional distribution of the errors. The formula below is valid under explicit conditional assumptions, not merely because the weights sum to one.

Result: Write \(Y_i=m(X_i)+\varepsilon_i\). Suppose, conditional on both the predictor values \(X_1,\ldots,X_n\) and the weights \(W=(W_{n1}(x),\ldots,W_{nn}(x))\), the errors satisfy \(E[\varepsilon_i\mid X_1,\ldots,X_n,W]=0\) and \(\operatorname{Cov}(\varepsilon_i,\varepsilon_j\mid X_1,\ldots,X_n,W)=0\) for \(i\ne j\). If their conditional variances are all \(\sigma^2\), then \[ \operatorname{Var}\!\left(\sum_{i=1}^n W_{ni}(x)Y_i\mid X_1,\ldots,X_n,W\right) =\sigma^2\sum_{i=1}^n W_{ni}(x)^2 =\frac{\sigma^2}{N_{\mathrm{eff}}(x)}. \]

Proof. Conditional on the predictors and weights, the signal \(\sum_i W_{ni}(x)m(X_i)\) is fixed, so only \(\sum_i W_{ni}(x)\varepsilon_i\) contributes to the conditional variance. Expanding the variance gives

$$ \begin{aligned} \operatorname{Var}\!\left(\sum_i W_{ni}(x)\varepsilon_i\mid X_1,\ldots,X_n,W\right) &=\sum_i W_{ni}(x)^2\operatorname{Var}(\varepsilon_i\mid X_1,\ldots,X_n,W)\\ &\quad+2\sum_{i<j}W_{ni}(x)W_{nj}(x) \operatorname{Cov}(\varepsilon_i,\varepsilon_j\mid X_1,\ldots,X_n,W)\\ &=\sigma^2\sum_i W_{ni}(x)^2. \end{aligned} $$

The cross-covariance terms vanish by assumption. The definition of \(N_{\mathrm{eff}}(x)\) gives the final equality. The conditional mean-zero assumption also ensures that the conditional mean prediction is the weighted signal average. \(\square\)

Worked Example: Variance Under Valid Conditional Assumptions

Suppose the weights are \((1/2,1/4,1/4)\), and, conditional on both the predictors and these weights, the errors have mean zero, variance \(4\), and zero pairwise covariances. Compute the conditional variance of the noise part of the prediction.

The sum of squared weights is \(1/4+1/16+1/16=3/8\). Hence the conditional variance is \(4(3/8)=3/2\). Equivalently, the effective support is \(1/(3/8)=8/3\), and \(4/(8/3)=3/2\). These calculations use the stated assumptions conditional on the weights as well as the predictors.

Common Mistake: Conditioning on Response-Dependent Weights

A common error is to assume that errors which are uncorrelated and mean zero conditional on the predictors must retain those properties after conditioning on weights. That conclusion is not automatic when the weights depend on the responses. Conditioning on a response-dependent weight can reveal information about the errors and change their conditional means, variances, or covariances.

For a direct counterexample, let \(X_1,X_2\) be fixed and let \(\varepsilon_1,\varepsilon_2\) be independent Rademacher variables, each equal to \(1\) or \(-1\) with probability \(1/2\). Set \(m(X_i)=0\), and choose weights \((1,0)\) if \(\varepsilon_1=1\), and \((0,1)\) otherwise. Given the predictors alone, both errors have mean zero and variance one, and their covariance is zero. But conditional on weights \((1,0)\), the prediction is \(\varepsilon_1=1\) with probability one, so its conditional variance is zero—not \(1\cdot(1^2+0^2)=1\). The weighted-variance identity is therefore not justified by predictor-conditional error assumptions alone. It can be used when its conditional assumptions hold, for example when weights are fixed independently of the estimation errors under the conditioning, but response adaptation must be addressed explicitly.

Key takeaway: Forest weights define a data-adaptive local averaging distribution. Neighborhood mass describes how much weight is near the query; effective support describes how concentrated the weights are. Neither summary alone proves consistency or guarantees a variance formula: those conclusions also require appropriate localization and conditional error assumptions.

Check Your Understanding

Use the definitions and arguments above to answer the following.

  1. Why do averaging normalized, nonnegative tree weight vectors produce normalized, nonnegative forest weights?
  2. What does \(1-A_{n,r}(x)\) measure, and where does it enter the local-averaging error bound?
  3. If \(k\) observations have positive weights, why can the effective support not exceed \(k\)?
  4. Can a large effective support alone establish that a forest prediction uses nearby observations? Explain.
  5. Why must a variance identity be justified conditional on the weights when weights may depend on responses?
Clinical Biostats