Bagging, Random Forests, Boosting

I. Ozkan

Spring 2025

Learning Objectives

Bagging: Bootstrap Aggregation

Bagging: Bootstrap Aggregation

\(\hat f_{bag}(x)=\frac{1}{B} \sum_{b=1}^{B} \hat f^{*b}(x)\)

When to Use

Bagging: Bootstrap Aggregation

Revisit: Boston Data

Revisit: Boston Data



Tree Predictions
Medv tree_1 tree_2 tree_3 tree_4 tree_mean
24.0 23.88 24.63 27.30 31.63 26.86
34.7 33.79 31.78 34.86 46.45 36.72
28.7 23.88 24.63 21.79 22.04 23.08
27.1 15.71 15.47 16.00 17.04 16.06
16.5 15.71 15.47 16.00 17.04 16.06
18.9 20.85 20.81 21.79 22.04 21.37

Bagging: Boston Data

Bagging Example Boston Data: Feature Interpretation

Bagging Example Boston Data: Feature Interpretation

Bagging: Discussion

Random Forest

Random Forest: Algorithm

  1. Given a training data set
  2. Select number of trees to build (n_trees)
  3. for i = 1 to n_trees do
    • 3.1 Generate a bootstrap sample of the original data
    • 3.2 Grow a regression/classification tree to the bootstrapped data
    • 3.3 for each split do
      • 3.3.1 Select m_try variables at random from all p variables
      • 3.3.2 Pick the best variable/split-point among the m_try
      • 3.3.3 Split the node into two child nodes
    • 3.4 end
    • 3.5 Use typical tree model stopping criteria to determine when a tree is complete (but do not prune)
  4. end
  5. Output ensemble of trees

Random Forest Example: Boston Data

OOB Error, 500 trees with m = 4 variables: 11.2995 
 

Random Forest Example: Boston Data (5 Vars)

OOB Error, 500 trees with 5 variables: 10.89118 
 

Random Forest: Variable Importance

Random Forest Example: Boston Data, Predictions

Random Forest Example: Boston Data

Random Forest: Tuning



Number of variables vs RMSE
mtry OOB Error
2 14.91960
3 12.14668
4 11.27344
6 10.80146
9 10.36396
13 10.71012

Boosting

Boosting

Boosting: A Toy Example (https://github.com/bgreenwell)

\(f(x)=sin(x)+\varepsilon, \; \varepsilon \sim N(0, 0.3^2)\)

Boosting: A Toy Example (https://github.com/bgreenwell)

Boosting: A Toy Example (https://github.com/bgreenwell)

Boosting Example: Boston Data

Boosting Example: Boston Data, Predictions

Boosting Example: Boston Data, Tuning

Parameter Grid
Only First Ten Rows
Lambda Tree Depth Min Obs. Bag %
0.01 1 5 0.65
0.05 1 5 0.65
0.10 1 5 0.65
0.01 3 5 0.65
0.05 3 5 0.65
0.10 3 5 0.65
0.01 5 5 0.65
0.05 5 5 0.65
0.10 5 5 0.65
0.01 1 10 0.65
Parameter Grid Results
Only First Ten Rows
Lambda Tree Depth Min Obs. Bag % Optimal Trees min RMSE
0.10 3 10 0.80 519 3.466070
0.05 3 10 0.80 928 3.549038
0.10 3 15 1.00 516 3.570331
0.05 3 10 1.00 579 3.603082
0.10 5 10 0.80 273 3.604136
0.05 3 10 0.65 818 3.617805
0.05 5 10 0.80 972 3.628066
0.05 3 15 1.00 763 3.630852
0.10 3 10 1.00 271 3.650064
0.10 3 15 0.80 387 3.687217

Boosting Example: Boston Data, Tuning

Relative Variable Importance
Only First Ten Most Influential Variables
Variable Rel. Influence
lstat 43.22172095
rm 31.67702890
dis 6.89444926
nox 5.24821280
ptratio 3.74173961
crim 3.28965497
age 2.53138349
black 0.98147906
tax 0.91887410
chas 0.57786684
rad 0.52248694
indus 0.33829170
zn 0.05681139

Boosting Example: Partial Effect Plot

Boosting Example: Predictions