By the end of this lecture, you should be able to:
interpret tree and forest predictions as local averages;
distinguish averaging tree predictions from pooling unnormalized tree kernels;
read a forest-kernel plot; and
explain how candidate predictors and terminal-node size affect local neighborhoods.
The previous lecture introduced the forest and its tuning parameters. We now look at which training observations contribute to a prediction, using the kernel examples from the original notes.
Kernel view of Random Forests
A tree can also be viewed as a local averaging rule. Write the training data as for . For tree , let be the number of copies of observation in the treeβs sample if it shares a leaf with target , and zero otherwise. With sampling without replacement, this is simply 1 or 0. For a regression forest with trees,
Each tree averages responses within one terminal node; the forest averages those tree predictions. The denominators may differ across trees because their terminal nodes contain different observations. The original lecture also considers the related pooled-kernel estimator
It pools the tree weights before normalizing, so it need not equal the usual forest average when leaf sizes differ. In the plots below, sampling is without replacement, so the kernel counts the trees in which a training observation was sampled and shares a leaf with the target. That count shows which observations are locally relevant to the fitted forest. Counting shared leaves for all pairs, without the sampling restriction, also gives a symmetric similarity for spectral clustering or kernel ridge regression.
The five-predictor sample follows with independent uniform predictors on . The noise is independent of the predictors. Only the first two predictors affect the mean. We compare six single-tree kernels for target . Each orange point is a sampled training observation that shares the targetβs terminal node in that tree.
As in the previous lecture, all forest fits use the RLT R package and its Python package. The node-size threshold is nmin in R and min_samples_leaf in Python. The plots show the first two coordinates, although trees may also split on the other three predictors.
Six one-tree neighborhoods. The navy cross is the target point.
The sets differ because the trees use different random subsamples. Stacking many trees gives a smoother description of which observations repeatedly share a leaf with the target.
For the same five-predictor sample, the next figure uses 500 trees, a node-size setting of 4, and an 80% sample without replacement for each tree. These are the settings in the older STAT 432 example.
For each target, we divide the kernel counts by their sum. Larger orange points indicate greater normalized weight. Both panels use the same size scale. Normalizing the counts prevents a larger number of trees from automatically enlarging every point. Node size, sample fraction, and mtry affect how the weights are distributed.
Forest-kernel weights for two target points, with a shared point-size scale.
The kernel depends on the fitted trees, so the local weighting changes with the target point. The plots show the pooled-kernel weights. They need not reproduce the usual forest prediction when terminal-node sizes differ.
Adaptiveness of Random Forest Kernel
A forest can adapt to a sparse signal. In the original lectureβs final example, with , while is noise. Both predictors are drawn independently and uniformly from , and the noise is independent of them. The supplied sample has 400 observations. Both forests use 500 trees, a node-size setting of 40, and an 80% sample without replacement. For target , compare the kernel when both predictors compete at each split with the kernel when only one randomly chosen predictor is available.
With mtry = 2, splits tend to favor , so influential observations stay close to the target in while spreading along . With mtry = 1, many splits must use , and the weights spread differently. This is the adaptiveness illustrated by the original kernel plots. The result is for one simulated sample; mtry should be chosen using prediction performance when fitting a model in practice.