Lesson 5.2 · 7 min read · about 45 min to master at a very slow pace
Model Complexity and Feature Selection
Complexity has many dials: number of features, coefficient size, depth, K. Why adding features always helps in-sample, why it eventually hurts out-of-sample, and how feature selection fits in.
Many dials, one idea
| Model | Complexity dial | More complex when... |
|---|---|---|
| Linear regression | Number of predictors; size of coefficients | More variables, bigger |
| Polynomial regression | Degree | Higher degree |
| K-nearest neighbours | Smaller (more local, wigglier) | |
| Decision tree | Depth | Deeper |
| K-means | Number of clusters | Larger |
| SVM | Cost ; kernel bandwidth | Larger |
More features: in-sample vs out-of-sample
Adding a predictor to OLS can never increase training RSS: at worst its coefficient is set to zero. So training error always prefers the biggest model. Choosing which features to keep must use validation data, cross-validation, or a criterion that penalises size (adjusted , AIC/BIC).
Ways to choose features
- Domain knowledge: fine when you genuinely know what's relevant.
- Subset selection: best subset, forward or backward stepwise (5.3).
- Shrinkage that selects: LASSO sets some coefficients exactly to zero (5.5).
The p-value trap
"We removed every variable with , refitted, and now all ." That's not a sound selection procedure. It ignores the uncertainty of the selection itself, makes the final p-values over-confident (they're reported as if no selection happened), and targets in-sample significance rather than out-of-sample prediction. Use CV-based stepwise selection or LASSO.
And the leakage trap
Feature selection is a learning step. It must happen inside each CV training fold, never on the full dataset first (lesson 2.8).
Cheatsheet
Select by p-values
Complexity dials
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.