Part 3

Bagging means bootstrap aggregating: train separately, then combine.

Bagging is a general ensemble recipe. Random Forest uses this recipe with decision trees and adds random feature selection.

The bagging recipe

Sequence question

Which should happen first: aggregate predictions from one tree, or train many trees on different bootstrap samples?

  1. Draw a bootstrap sample of rows.
  2. Fit a base learner using that sample.
  3. Repeat for \(B\) learners independently.
  4. Aggregate their predictions.
\[\hat f_{bag}(x)=\frac{1}{B}\sum_{b=1}^B f_b(x)\]

Intuition: every learner is a slightly different answer to the same problem; the final answer is their consensus.

Worked classification vote

Vote before calculation

Three trees predict Approved, Approved, and Declined. What does hard voting return?

TreePredictionLeaf probability of Approved
1Approved4/5 = 0.80
2Approved3/4 = 0.75
3Declined1/4 = 0.25
\[\text{hard vote}=\operatorname{mode}(A,A,D)=A\]
\[\text{soft probability}=\frac{0.80+0.75+0.25}{3}=0.60\]

Intuition: hard voting keeps only each tree's final label. Soft voting preserves how confident the trees were. Scikit-learn's RandomForestClassifier averages the trees' class probabilities.

Worked regression average

Average question

Five trees predict 48, 55, 72, 50, and 65. What single number should bagging report?

\[\hat y=\frac{48+55+72+50+65}{5}=58\]

The 72 is not allowed to dominate the answer by itself. It contributes one vote among five numeric opinions.

mean = 58tree predictions

Individual trees can be jagged and variable. Their average is usually more stable, though it is still made from tree-shaped regions.

Bagging can reduce variance, but averaging cannot repair a shared systematic mistake.

Previous: BootstrapNext: Features