Classification and Regression Trees (CART)
Tree-based methods for regression and classification involve:
Key Methods:
Advantages ✓
Disadvantages ✗
Solution: Ensemble methods (Bagging, Random Forests, Boosting) dramatically improve performance!
Predicting log salary based on Years of experience and Hits:
Years < 4.5
/ \
Yes / \ No
/ \
5.11 Hits < 117.5
/ \
Yes / \ No
/ \
6.00 6.74
Three regions created:
Recursive Binary Splitting (greedy, top-down approach):
Objective: Find boxes R₁, …, Rⱼ that minimize:
\[\sum_{j=1}^{J} \sum_{i \in R_j} (y_i - \hat{y}_{R_j})^2\]
where \(\hat{y}_{R_j}\) is the mean response in region Rⱼ
Prediction for new observation:
Assign it to one of the regions and predict the mean of training observations in that region
Cannot use RSS for classification. Instead use:
Classification Error Rate: \[E = 1 - \max_k(\hat{p}_{mk})\]
Gini Index (preferred for growing trees): \[G = \sum_{k=1}^{K} \hat{p}_{mk}(1 - \hat{p}_{mk})\]
Cross-Entropy/Deviance: \[D = -\sum_{k=1}^{K} \hat{p}_{mk} \log \hat{p}_{mk}\]
where \(\hat{p}_{mk}\) = proportion of training observations in region m from class k
Problem: Large trees overfit → poor test performance
Solution: Cost Complexity Pruning
Minimize: \[\sum_{m=1}^{|T|} \sum_{i \in R_m} (y_i - \hat{y}_{R_m})^2 + \alpha|T|\]
Heart Disease Classification (303 patients, 13 predictors)
Key predictors identified:
Result: Cross-validation selects tree with 6 terminal nodes
Test error ≈ 25% (vs. 45% for single large tree)
Linear Boundary
|
● | ○
●● | ○○
●●●●●|○○○○
─────+─────
Works well when true boundary is linear
Non-linear Boundary
○○○|●●●
○○ | ●●
○○──┼──●
● | ○
Trees excel when relationships are complex/non-linear
Rule of thumb: Try both approaches! Trees are better for highly non-linear relationships
Key Insight: Averaging reduces variance!
If we have n independent observations Z₁, …, Zₙ with variance σ²:
\[\text{Var}(\bar{Z}) = \frac{\sigma^2}{n}\]
Bagging Algorithm:
\[\hat{f}_{\text{bag}}(x) = \frac{1}{B} \sum_{b=1}^{B} \hat{f}^{*b}(x)\]
For classification: Use majority vote across B trees
Clever trick: Each bagged tree uses ≈ 2/3 of observations
Advantage: No need for separate cross-validation!
Problem with Bagging: Trees can be highly correlated
Random Forest Solution:
At each split, randomly select m predictors as split candidates (from p total)
Why does this help?
Forces diversity among trees → reduces correlation → lower variance when averaging!
Heart Disease Example:
Gene Expression Example (15 classes, 500 predictors):
Random Forests consistently outperform bagging, especially with many correlated predictors!
Key Difference: Trees grown sequentially, each fixing previous errors
Boosting Algorithm:
Key parameters:
Teacher-Student Analogy:
Result: Slow, steady learning → very accurate final model
Unlike bagging/RF: can overfit if B too large (but slowly)
Gene Expression Data (15 classes, 500 predictors):
California Housing Data:
Boosting with depth=6 achieves lowest test error among all methods
Boosting often wins in competitions and real applications!
| Method | Key Parameters | Typical Values |
|---|---|---|
| Single Tree | α (pruning) | Use CV |
| Bagging | B (# trees) | Large (≈ 500), doesn’t overfit |
| Random Forest | B (# trees) m (# predictors per split) |
B ≈ 500 m = √p (classification) m = p/3 (regression) |
| Boosting | B (# trees) λ (learning rate) d (tree depth) |
Use CV for B λ = 0.01 or 0.001 d = 1 to 6 |
How to measure which predictors matter most?
For Bagging/Random Forest (Regression):
For Bagging/Random Forest (Classification):
For Boosting:
Common Uses in Economics:
Advantages for economists:
Single Decision Tree
Ensemble Methods
Specific Ensemble Choice:
# Single Tree
library(tree)
tree_model <- tree(y ~ ., data = train)
cv_tree <- cv.tree(tree_model)
pruned <- prune.tree(tree_model, best = 6)
# Random Forest
library(randomForest)
rf_model <- randomForest(y ~ ., data = train,
mtry = sqrt(p), ntree = 500)
# Boosting
library(gbm)
boost_model <- gbm(y ~ ., data = train,
distribution = "gaussian",
n.trees = 5000, interaction.depth = 4,
shrinkage = 0.01)Single trees: Simple, interpretable, but low accuracy
Ensemble methods dramatically improve performance:
Trade-off: Accuracy vs. Interpretability
Random Forest: Usually best “out-of-box” performance
Boosting: Often achieves highest accuracy with tuning
Economic applications: Powerful for prediction when relationships are complex
| Aspect | Single Tree | Bagging | Random Forest | Boosting |
|---|---|---|---|---|
| Interpretability | ★★★★★ | ★ | ★ | ★ |
| Accuracy | ★★ | ★★★★ | ★★★★★ | ★★★★★ |
| Speed | ★★★★★ | ★★★ | ★★★ | ★★ |
| Tuning Required | ★★ | ★ | ★★ | ★★★★ |
| Overfitting Risk | ★★★★ | ★ | ★ | ★★★ |
Key Resources:
James, Witten, Hastie, Tibshirani (2013). An Introduction to Statistical Learning (Chapter 8)
Hastie, Tibshirani, Friedman (2009). The Elements of Statistical Learning (Chapters 9, 10, 15)
Breiman (2001). “Random Forests” Machine Learning
Friedman (2001). “Greedy Function Approximation: A Gradient Boosting Machine” Annals of Statistics
R Packages: tree, rpart, randomForest, gbm, xgboost
Contact Information:
[Your email/office hours]
Additional Resources:
Additional mathematical details and proofs for interested students
For regression trees, at each split we choose predictor j and cutpoint s to minimize:
\[\sum_{i: x_i \in R_1(j,s)} (y_i - \hat{y}_{R_1})^2 + \sum_{i: x_i \in R_2(j,s)} (y_i - \hat{y}_{R_2})^2\]
where:
This is done for all possible j and s (greedy search)
Mathematical Intuition:
If we had multiple training sets, we could:
This would have lower variance than any single \(\hat{f}^b(x)\)
Bootstrap approximation:
Since we have only one training set, create B bootstrap samples to simulate having B different training sets!
Problem: If there’s a very strong predictor, most/all bagged trees will use it at the first split
→ All trees look similar → highly correlated → averaging doesn’t reduce variance much
Example: If correlation between trees = ρ, then variance of average:
\[\text{Var}(\bar{X}) = \rho\sigma^2 + \frac{1-\rho}{B}\sigma^2\]
As B → ∞, first term remains → correlation limits improvement
Random Forest solution: Force decorrelation by limiting predictor choice at each split
CART Models in Economics