You understand bias and variance; regularization is the practical lever that penalizes complexity so models generalize. It appears in linear models (Ridge, Lasso), tree pruning, SVM margin, boosting learning rate, and—in Volume 06—weight decay and dropout in neural networks.
Learning Objectives
By the end of this lesson, students should be able to:
- Define regularization as a penalty on model complexity added to the loss.
- Explain how regularization reduces variance at the cost of some bias.
- Identify the regularization hyperparameter (λ,
alpha,C) in common algorithms. - Tune regularization strength with cross-validation.
- Map classical penalties (L1, L2) to sklearn estimators in upcoming lessons.
The Core Idea
Instead of minimizing loss alone, we minimize loss + penalty:
Objective = Data Loss + λ × Complexity Penalty
Larger λ (or alpha in sklearn) shrinks or sparsifies parameters, discouraging fits that exploit noise. Too much regularization causes underfitting; too little invites overfitting.
| Algorithm | Regularization knob | Effect |
|---|---|---|
| Ridge / Lasso / ElasticNet | alpha | Weight shrinkage / sparsity |
| Logistic regression | C (inverse strength) | Larger C = less penalty |
| Decision tree | max_depth, min_samples_leaf | Limits tree complexity |
| SVM | C | Margin vs misclassification tradeoff |
| Neural net (Vol. 06) | weight decay, dropout | Parameter and activation penalties |
Sweep alpha or C with GridSearchCV inside pipelines. The regularization hyperparameter is as important as model choice—defaults are rarely optimal for your signal-to-noise ratio.
Tuning Regularization Strength
Implicit vs Explicit Regularization
Explicit penalties
- L1, L2 on weights
- ElasticNet combination
- Added directly to loss
Implicit / structural
- Early stopping (stop before overfit)
- Bagging averages high-variance models
- Bayesian priors on parameters
- Data augmentation as regularization
L2 penalizes large coefficients equally in raw feature units. A feature in dollars dominates one in 0–1 range. Fit StandardScaler in a pipeline before Ridge/Lasso so penalties are fair.
Knowledge Check
- Short Answer: What does increasing λ generally do to variance? Answer: Reduces it.
- True/False: In sklearn Ridge, larger
alphameans weaker regularization. Answer: False—stronger penalty. - Multiple Choice:
Cin SVM is: (a) penalty strength, (b) inverse regularization, (c) learning rate. Answer: (b). - Short Answer: Why pipeline scaling before L2? Answer: So penalties apply fairly across feature scales.
- Short Answer: Name one non-L1/L2 regularization. Answer: e.g., tree depth limit or early stopping.
- True/False: Regularization adds a complexity penalty to the training loss. Answer: True.
- Multiple Choice: Too large λ typically: (a) overfits, (b) underfits, (c) removes noise. Answer: (b).
- Short Answer: How should you choose
alpha/ λ? Answer: Cross-validation on training data, not the test set. - True/False: Weight decay in neural nets is an L2-style regularizer. Answer: True.
- Multiple Choice: Larger Ridge
alpha/ smaller SVMCmeans: (a) weaker regularization, (b) stronger regularization, (c) identical names. Answer: (b).
Key Takeaways
- Regularization = loss + complexity penalty controlled by λ /
alpha. - It trades a bit of bias for lower variance and better generalization.
- Always tune the strength with cross-validation in pipelines.
- Scale features before weight penalties.
- Next: L1 — sparsity-inducing regularization.
Hands-on idea: Plot validation MSE vs alpha on log scale for Ridge on a wide dataset. Students identify under- and over-regularized regions.
Discussion prompt: Is early stopping in deep learning “regularization”? Defend yes or no.
Recap: Regularization trades a little bias for less variance by penalizing complexity—tune strength with CV. Continue with L1.