Blame

e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
1
# 7. Regularization and high-dimensional inference
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
2
3
You often do not have a handful of clean regressors. There can be many candidate predictors, sometimes more than observations, and they are correlated. Ordinary least squares overfits or breaks down in that regime. Regularization tames it by shrinking the coefficients, and this is where regularized regression meets classical statistics most directly. It also carries a warning: selecting variables and then doing inference on the same data invalidates the classical standard errors, which matters whenever the goal is a causal estimate rather than a prediction.
4
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
5
Throughout we write the regression coefficients as $\beta$, the parameters $\theta$ of the linear model from the [linear regression module](/en/Machine%20Learning/05%20Linear%20regression).
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
6
7
**Objectives**
8
- See why ordinary least squares fails with many correlated regressors.
9
- Define ridge (L2) and lasso (L1) regression and the role of the penalty $\lambda$.
10
- Understand why the lasso produces sparse, variable-selecting solutions.
11
- Choose the penalty $\lambda$ by cross-validation.
12
- Recognize why naive post-selection inference is invalid, and know the standard corrections.
13
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
14
## 7.1 Why regularize
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
15
16
When the number of regressors $p$ is large relative to the sample size $n$, the least-squares fit chases noise and its coefficients have huge variance. With correlated regressors the matrix $X^T X$ is nearly singular, so small data changes swing the estimates wildly, and when $p > n$ it is singular and OLS has no unique solution at all. Regularization accepts a little bias in exchange for a large cut in variance, the trade-off from [General concepts](/en/Machine%20Learning/02%20General%20concepts).
17
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
18
## 7.2 Ridge regression (L2)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
19
20
Ridge adds a squared-norm penalty on the coefficients to the least-squares objective:
21
22
$$\boxed{ \hat{\beta}_{\text{ridge}} = \arg\min_{\beta} \; \|y - X\beta\|_2^2 + \lambda \|\beta\|_2^2 }$$
23
24
It has a closed form that is always invertible for $\lambda > 0$, which is exactly what rescues the collinear and $p > n$ cases:
25
26
$$\boxed{ \hat{\beta}_{\text{ridge}} = \left(X^T X + \lambda I\right)^{-1} X^T y }$$
27
28
Ridge shrinks all coefficients smoothly toward zero but never sets them exactly to zero, so it stabilizes rather than selects.
29
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
30
## 7.3 Lasso regression (L1)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
31
32
The lasso replaces the squared penalty with an absolute-value penalty:
33
34
$$\boxed{ \hat{\beta}_{\text{lasso}} = \arg\min_{\beta} \; \|y - X\beta\|_2^2 + \lambda \|\beta\|_1 }$$
35
36
This small change has a large consequence: the lasso drives some coefficients to exactly zero, so it performs variable selection while it fits. The reason is geometric. The constraint region $\|\beta\|_1 \le t$ is a diamond with corners on the axes, and the elliptical loss contours tend to first touch it at a corner, where one coordinate is zero.
37
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
38
![L1 versus L2 constraint geometry](/en/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference/a/l1-l2-geometry.png)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
39
40
*The rounded L2 ball is touched off the axes, keeping every coefficient nonzero, while the L1 diamond is touched at a corner, setting a coefficient to exactly zero.*
41
42
As the penalty grows, more coefficients cross to zero, tracing the regularization path from the full model to the empty one.
43
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
44
![Lasso regularization path](/en/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference/a/regularization-path.png)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
45
46
*Each coefficient shrinks as $\lambda$ increases and then hits exactly zero, so the lasso yields a compact, interpretable subset of regressors.*
47
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
48
## 7.4 Elastic net
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
49
50
The elastic net blends the two penalties, keeping the lasso's selection while borrowing the ridge's stability with correlated regressors:
51
52
$$\boxed{ \hat{\beta}_{\text{en}} = \arg\min_{\beta} \; \|y - X\beta\|_2^2 + \lambda\left(\alpha \|\beta\|_1 + (1 - \alpha)\|\beta\|_2^2\right) }$$
53
54
with $\alpha \in [0, 1]$ mixing selection ($\alpha = 1$, lasso) and shrinkage ($\alpha = 0$, ridge).
55
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
56
## 7.5 Choosing the penalty
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
57
58
The penalty $\lambda$ is a hyperparameter, so it is chosen by cross-validation from the [previous module](/en/Machine%20Learning/03%20Model%20evaluation%20and%20validation): fit over a grid of $\lambda$ values and keep the one with the lowest cross-validated error, or the largest $\lambda$ within one standard error of the best for a simpler model. Larger $\lambda$ means more shrinkage, more bias, and less variance.
59
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
60
## 7.6 The inference caveat
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
61
62
Prediction is not inference, and this is the point that is easy to miss. Suppose you select regressors with the lasso and then run ordinary least squares on the chosen subset and report textbook standard errors. Those standard errors are wrong. They ignore that the data was already used to pick the variables, so the confidence intervals are too narrow and the p-values are not valid, a form of the winner's curse. Three corrections are standard:
63
64
- **Sample splitting.** Select the variables on one part of the data and estimate and do inference on another, so the selection does not contaminate the standard errors.
65
- **Debiased (desparsified) lasso.** Add a correction term to the lasso estimate that removes the shrinkage bias and restores an asymptotically valid confidence interval for each coefficient.
66
- **Post-double-selection** (Belloni, Chernozhukov, and Hansen). To estimate the effect of a treatment with many controls, select the controls that predict the outcome and the controls that predict the treatment, then estimate the effect on the union of both sets.
67
68
$$\boxed{ \text{select for prediction} \;\ne\; \text{valid inference on a coefficient} }$$
69
70
*Remark:* these ideas are the doorway to causal machine learning, where flexible learners estimate nuisance functions while a correction preserves valid inference on the parameter of interest. Regularization is superb for prediction, but for a causal parameter you need one of these corrections, not the raw penalized coefficients.
71
72
*With shrinkage and selection covered, the next module takes a different route to a good decision boundary, the maximum-margin classifier, before we turn to trees and ensembles.*
73
74
---
e0287e lugonthier 2026-07-02 15:52:15
Add new content and images for machine learning and mathematics modules - Added images for regularization and high-dimensional inference. - Introduced Support Vector Machines (SVM) module with detailed explanations and images. - Created Decision Trees and Ensemble Methods module with comprehensive content and illustrations. - Added a Mathematics overview module and a refresher on mathematical concepts essential for machine learning. - Included SVG diagrams for Bayes' rule and multivariate Gaussian distribution.
75
Next: [Support Vector Machines](/en/Machine%20Learning/08%20Support%20Vector%20Machines) · [Course overview](/en/Machine%20Learning)