Lesson 5.3 · 9 min read · about 50 min to master at a very slow pace
Best Subset and Stepwise Selection
Best subset selection tries every combination of predictors; forward and backward stepwise approximate it greedily. The algorithms step by step, how many models each fits, and a worked forward-stepwise example.
The L0 penalty
Subset selection penalises the number of non-zero coefficients:
Best subset selection
- For each size : fit all models with exactly predictors and keep the one with the lowest training RSS. Call it .
- Choose among using a measure that accounts for complexity: validation or CV error, adjusted , AIC/BIC. Not training RSS, which always favours .
Benefit: directly implements parsimony and finds the best subset of each size. Problem: it fits models. : 1,024. : over a million. : hopeless.
Greedy approximations
| Forward stepwise | Backward stepwise |
|---|---|
|
|
Models fitted: . For : 56 instead of 1,024; for : 211 instead of 1,048,576.
Trade-off: stepwise isn't guaranteed to find the best subset. Once forward stepwise adds a variable, it never removes it, even if a later combination would be better without it.
Worked example: forward stepwise by hand
Three candidate predictors A, B, C. TSS .
- Step 0: (mean only): RSS .
- Step 1: one-variable models: A 60, B 45, C 80. Keep B: .
- Step 2: add one more to B: A+B 30, B+C 40. Keep .
- Step 3: : RSS 28.
Training RSS keeps falling (100, 45, 30, 28), as it always does. Now compare by validation RMSE: 10.0, 7.0, 5.5, 5.8. Choose .
Models fitted: , versus for best subset. The gap grows explosively with .
Cheatsheet
Forward stepwise
Best subset
Model counts
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.