Blame

d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
1
# 2. General concepts
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
3
The introduction fixed the notation and named the learning paradigms. Before fitting any particular model, this module covers what learning actually means. Making a model fit the data it has seen is easy, making it perform on data it has never seen is the whole game. Polynomial regression serves as the running example, and the module closes with the reason geometric intuition fails in high dimension.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
5
## 2.1 Supervised versus unsupervised learning
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
7
The [Introduction](/en/Machine%20Learning/01%20Introduction) named the paradigms by their feedback signal. Formally, supervised learning starts from labelled pairs $\{(x^{(i)}, y^{(i)})\}_{i=1}^{m}$ and searches a family of hypotheses for the $h_w$ whose predictions sit closest to the targets, closeness being measured by a loss function. Unsupervised learning has only the inputs $x^{(i)}$, so its objectives are built from the inputs alone: compact groups, informative directions, regions of high density.
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
8
9
Everything in this module is stated for the supervised case, which occupies the rest of the course. The questions it answers (how well does this model generalize, how complex should it be, how do I choose between candidates) arise unchanged in the unsupervised setting.
10
11
## 2.2 Minimizing a loss: polynomial regression
12
13
### 2.2.1 Loss function
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
14
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
15
A loss function $L(z, y)$ is defined as a scalar penalty comparing a raw model score $z$ (or a predicted probability $\hat{y}$) against the target $y$. Smaller is better. Each family of models is characterized by its loss.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
16
17
| Loss | Formula $L(z,y)$ | Used by |
18
| --- | --- | --- |
19
| Least squared error | $\tfrac{1}{2}(y-z)^2$ | Linear regression |
20
| Logistic | $\log\!\left(1+\exp(-yz)\right)$ | Logistic regression |
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
21
| Cross-entropy | $-\left[\,y\log\hat{y}+(1-y)\log(1-\hat{y})\,\right]$ | Neural networks |
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
22
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
23
*Remark:* $z$ denotes a raw score such as $w^T x$, whereas $\hat{y} \in (0,1)$ denotes a predicted probability, the model's estimate of the label $y$. The cross-entropy row takes a probability $\hat{y}$, not a raw score.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
24
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
25
![Margin-based loss functions](/en/Machine%20Learning/02%20General%20concepts/a/loss-functions.png)
26
27
*Margin-based losses, each a convex surrogate for the 0-1 loss that penalizes small or negative margins.*
28
29
### 2.2.2 Cost function
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
30
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
31
The cost $J(w)$ is defined as the sum of the per-example losses over the whole training set of $m$ examples:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
33
$$\boxed{\,J(w)=\sum_{i=1}^{m} L\!\left(h_w(x^{(i)}),\,y^{(i)}\right)\,}$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
35
Training a model means choosing $w$ to minimize $J(w)$. The algorithms that carry out this minimization (closed forms, gradient descent) arrive with the model modules. This module asks a different question: what does a low value of $J(w)$ actually prove?
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
36
37
*Remark:* the factor $\tfrac{1}{2}$ in the squared error is a convention that cancels with the exponent when differentiating, leaving a clean gradient.
38
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
39
### 2.2.3 The running example: polynomial regression
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
41
To make everything concrete, take a single input $x$ and fit a polynomial of degree $d$ under the squared loss:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
43
$$\boxed{ h_w(x) = w^T \phi(x) = \sum_{j=0}^{d} w_j\, x^{j}, \qquad \phi(x) = (1, x, x^2, \dots, x^d) }$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
45
The model stays linear in $w$, so least squares applies unchanged (the closed form is derived in [Linear regression](/en/Machine%20Learning/04%20Linear%20regression)). The degree $d$ is not fitted along with $w$: it is fixed before fitting and decides how flexible the curve is allowed to be. A knob of that kind, chosen rather than learned, is called a hyperparameter, and $d$ is our first one.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
47
![Polynomial fits of degree 1, 3, and 9](/en/Machine%20Learning/02%20General%20concepts/a/polynomial-fits.png)
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
48
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
49
*The same noisy sample fitted three ways. Degree 1 is too rigid to follow the trend, degree 3 captures it, and degree 9 weaves through every training point.*
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
51
## 2.3 Training performance versus generalization
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
52
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
53
### 2.3.1 Generalization error
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
54
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
55
The quantity we care about is the generalization error, the expected loss on a fresh draw from the same population:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
57
$$\boxed{ R(h) = \mathbb{E}_{(x, y)}\left[ L\!\left(h(x), y\right) \right] }$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
59
We cannot observe it, so we estimate it. The tempting estimate is the training error, the average loss on the data used to fit $h$. It is biased downward: the model has already adapted to that particular sample, so it scores itself too kindly.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
61
$$\boxed{ \hat{R}_{\text{train}}(h) = \frac{1}{m}\sum_{i=1}^{m} L\!\left(h(x^{(i)}), y^{(i)}\right) \;\le\; R(h) \ \text{(in expectation)} }$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
62
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
63
### 2.3.2 Underfitting and overfitting
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
65
Back to the polynomials. The degree-1 fit underfits: it lacks the capacity to represent the trend, so it scores badly on the training points and on new points alike. The degree-9 fit overfits: it has capacity to spare, drives the training error to zero by weaving through the noise, and pays for it on fresh data. It has the lowest training error of the three fits and is also the worst model. The good model sits in between.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
66
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
67
![Training versus validation error as capacity grows](/en/Machine%20Learning/02%20General%20concepts/a/train-vs-validation.png)
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
69
*As the degree grows, the training error falls monotonically while the validation error falls, bottoms out, and rises again. The best degree sits at the bottom of the U.*
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
70
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
71
This is the bias-variance trade-off. A rigid model is biased: it is systematically off, whichever sample it is trained on. A flexible model has high variance: its fit swings with every resample of the noise. Raising capacity trades bias for variance, and generalization is best where the two balance.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
73
*Remark:* training error is not evidence of quality. Past the sweet spot it is evidence of memorization, and only performance on unseen data can tell the difference.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
75
## 2.4 Regularization
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
77
Choosing the degree is a coarse dial: capacity jumps by whole integers. A finer control keeps a flexible family but makes complexity expensive inside the cost itself, by adding a penalty $\Omega(w)$ scaled by a strength $\lambda \ge 0$:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
78
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
79
$$\boxed{\,J_\lambda(w)=\sum_{i=1}^{m} L\!\left(h_w(x^{(i)}),\,y^{(i)}\right) + \lambda\,\Omega(w)\,}$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
80
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
81
The classic choice is the squared norm $\Omega(w) = \lVert w \rVert_2^2$, the ridge penalty. The degree-9 fit only weaves through every point by using huge coefficients that cancel each other between the training points. The penalty makes those coefficients costly, so the minimizer trades a little training error for a much smoother curve. At $\lambda = 0$ the overfitted fit returns, as $\lambda \to \infty$ the curve flattens toward underfitting: $\lambda$ sweeps the same bias-variance dial as the degree, but continuously.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
83
*Remark:* regularization does not decide the right complexity for you, it converts a discrete choice ($d$) into a continuous one ($\lambda$) that is easier to tune. $\lambda$ is a hyperparameter like the degree, chosen by the validation machinery of the next section. Where the penalty comes from (a prior on $w$, via maximum a posteriori) and what the L1 variant adds are the subjects of [Probabilistic formulation](/en/Machine%20Learning/03%20Probabilistic%20formulation) and [Linear regression](/en/Machine%20Learning/04%20Linear%20regression).
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
84
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
85
## 2.5 Hyperparameters, validation, and cross-validation
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
86
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
87
### 2.5.1 Training, validation, and test sets
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
88
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
89
Hyperparameters cannot be chosen on the training error, which only rewards more capacity. The fix is to keep data the model never touched during fitting. The standard split has three disjoint roles:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
90
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
91
| Set | Used for | Touched |
92
| --- | --- | --- |
93
| Training | fitting the model parameters | every fit |
94
| Validation | choosing the model and its hyperparameters | many times |
95
| Test | reporting one honest final estimate | exactly once |
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
96
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
97
*Remark:* the test set is sacred. Every time a choice is guided by test performance, the test set quietly becomes part of training and its estimate turns optimistic.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
98
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
99
### 2.5.2 Cross-validation
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
100
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
101
Samples are often small, and a single train/validation split both wastes data and gives a noisy estimate. k-fold cross-validation reuses the data: partition it into $K$ folds, and for each fold train on the other $K-1$ and validate on the held-out fold. The cross-validation error averages the $K$ rounds:
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
102
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
103
$$\boxed{ \text{CV}_K = \frac{1}{K}\sum_{k=1}^{K} \frac{1}{|F_k|}\sum_{i \in F_k} L\!\left(h^{(-k)}(x^{(i)}), y^{(i)}\right) }$$
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
104
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
105
where $h^{(-k)}$ is trained on all folds except $F_k$. Taking $K = m$ gives leave-one-out cross-validation. Common choices are $K = 5$ or $K = 10$, trading computation against a lower-variance estimate.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
106
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
107
![k-fold cross-validation](/en/Machine%20Learning/02%20General%20concepts/a/cross-validation.svg)
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
108
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
109
*Each round holds out one fold for validation and trains on the rest, and the reported score is the average across folds.*
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
110
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
111
### 2.5.3 Model and hyperparameter selection
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
112
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
113
Cross-validation is how we tune. Fit each candidate (a model family, a tree depth, the polynomial degree $d$, or the penalty $\lambda$) and keep the one with the lowest validation or CV error. Only then, once the choice is frozen, do we touch the test set to report a final number.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
114
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
115
*Remark:* choosing the winner on the test set inflates the estimate. With enough candidates one will look good by chance alone, the winner's curse, so selection and final evaluation must use different data.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
116
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
117
## 2.6 Regression metrics: how far off, on average
118
119
The U-curve of section 2.3 already used a regression metric without naming it: the RMSE. For regression the raw material is the residual $y - \hat{y}$ between the label and the prediction $\hat{y} = h_w(x)$, and the metrics differ in how they aggregate the residuals, here for five predictions:
120
121
| | $y$ | $\hat{y}$ | $y - \hat{y}$ |
122
| --- | --- | --- | --- |
123
| example 1 | 10 | 12 | $-2$ |
124
| example 2 | 14 | 13 | $1$ |
125
| example 3 | 8 | 9 | $-1$ |
126
| example 4 | 12 | 9 | $3$ |
127
| example 5 | 16 | 17 | $-1$ |
128
129
| Metric | Formula | Here | Reads as |
130
| --- | --- | --- | --- |
131
| MSE | $\frac{1}{m}\sum_i \left(y^{(i)} - \hat{y}^{(i)}\right)^2$ | $3.2$ | the squared-error loss itself, in squared units |
132
| RMSE | $\sqrt{\text{MSE}}$ | $\approx 1.8$ | typical error, in the target's own units |
133
| MAE | $\frac{1}{m}\sum_i \left\lvert y^{(i)} - \hat{y}^{(i)} \right\rvert$ | $1.6$ | average miss, robust to outliers |
134
| $R^2$ | $1 - \sum_i \left(y^{(i)} - \hat{y}^{(i)}\right)^2 \big/ \sum_i \left(y^{(i)} - \bar{y}\right)^2$ | $0.6$ | variance explained, against predicting the mean |
135
136
The mean here is $\bar{y} = 12$. Squaring makes the MSE and RMSE quadratic in each residual, so one large error dominates them, while the MAE grows only linearly:
137
138
![RMSE versus MAE under an outlier](/en/Machine%20Learning/02%20General%20concepts/a/regression-metrics.png)
139
140
*The same fit before and after a single outlier: the RMSE nearly triples while the MAE moves far less. Whether that sensitivity is a feature or a flaw depends on how costly large errors are in the application.*
141
142
*Remark:* $R^2$ compares the model against the laziest baseline, predicting the mean $\bar{y}$ for every input. $R^2 = 1$ is a perfect fit, $R^2 = 0$ is no better than the baseline, and a negative $R^2$, worse than the baseline, is validation's way of saying the model learned nothing. Unlike the RMSE and MAE it is scale-free, so it compares across targets in different units.
143
144
## 2.7 Classification metrics: beyond a single error rate
145
146
For classification, the number the validation reports need not be the raw loss. A trained classifier makes four kinds of calls: true and false positives, true and false negatives. Counting them on held-out data gives the confusion matrix, here for 29 examples:
147
148
| | predicted $+$ | predicted $-$ | total |
149
| --- | --- | --- | --- |
150
| actually $+$ | TP = 11 | FN = 3 | 14 |
151
| actually $-$ | FP = 5 | TN = 10 | 15 |
152
153
Every headline metric is a ratio of these four cells:
154
155
| Metric | Formula | Here | Reads as |
156
| --- | --- | --- | --- |
157
| Accuracy | $(TP+TN)/\text{total}$ | $21/29 \approx 0.72$ | fraction correct overall |
158
| Recall (true positive rate) | $TP/(TP+FN)$ | $11/14 \approx 0.79$ | positives that were found |
159
| Precision | $TP/(TP+FP)$ | $11/16 \approx 0.69$ | flagged positives that are right |
160
| Specificity | $TN/(TN+FP)$ | $10/15 \approx 0.67$ | negatives that were kept |
161
| False positive rate | $FP/(FP+TN)$ | $5/15 \approx 0.33$ | negatives that were flagged |
162
| F1 score | $2\,\text{Pr}\cdot\text{Re}/(\text{Pr}+\text{Re})$ | $\approx 0.73$ | precision-recall balance |
163
164
*Remark:* accuracy alone can mislead. With 1% positives, always predicting "negative" scores 99% accuracy while finding nothing. Precision and recall keep score where it matters.
165
166
A classifier that outputs a score or a probability does not produce one confusion matrix but a family of them: sliding the decision threshold trades false positives against false negatives.
167
168
![One threshold, four outcomes](/en/Machine%20Learning/02%20General%20concepts/a/threshold-metrics.png)
169
170
*Everything right of the threshold is called positive. Pushing the threshold right shrinks the false positives (orange area) but grows the false negatives (blue area), and vice versa.*
171
172
Sweeping the threshold and plotting the trade-off gives the ROC curve (recall against false positive rate, perfect is the top-left corner) and the precision-recall curve (perfect is the top-right corner). Two classifiers are compared by their whole curves, or by the area under them, rather than by a single threshold's numbers.
173
174
![ROC and precision-recall curves](/en/Machine%20Learning/02%20General%20concepts/a/roc-pr-curves.png)
175
176
*Each point on a curve is one threshold: $T_1$ permissive, $T_3$ strict. The closer the curve bends toward its perfect corner, the better the classifier at every trade-off.*
177
178
*Remark:* this is what "a metric matched to the problem" means: compute these on the validation folds above to choose a model, and once, on the test set, to report it.
179
180
## 2.8 Common validation pitfalls
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
181
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
182
Honest validation is harder than it looks, and real data often breaks the usual assumptions in three ways.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
183
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
184
- **Data leakage.** Information about the target leaks into the features. Standardizing with statistics computed on the full sample, or including a variable realized after the outcome, lets the model peek at the answer. Any preprocessing must be fit on the training folds only.
185
- **Look-ahead bias.** Using information that was not yet available at the moment of prediction, which arises whenever the data is time-ordered, produces backtests that cannot be reproduced live.
186
- **Dependence.** Many datasets are serially correlated (time series) or grouped (several observations that share a unit). Shuffling them into random folds mixes near-identical neighbours across train and validation, so the estimate is far too optimistic.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
187
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
188
For time series, use a rolling-origin (blocked) scheme so the model is only ever tested on data that comes after its training window. For grouped data, hold out whole units (grouped cross-validation) so no unit appears on both sides.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
189
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
190
![Time-series cross-validation](/en/Machine%20Learning/02%20General%20concepts/a/time-series-cv.svg)
191
192
*In a rolling-origin scheme the training window grows forward in time and the model is validated on the next block, never on shuffled data.*
193
194
*Remark:* the honest question behind every split is the same. Would this have been knowable at the time, from data the model actually had?
195
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
196
## 2.9 The curse of dimensionality
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
197
198
Everything above rests on the sample standing in for the population near the points that matter. In high dimension that assumption degrades, and it degrades fast. Suppose the inputs fill the unit hypercube $[0,1]^d$ and we want a neighbourhood around a point that captures a fraction $r$ of the data. A sub-cube containing a fraction $r$ of the volume must have edge length:
199
200
$$\boxed{ e_d(r) = r^{1/d} }$$
201
202
In one dimension, capturing 1% of the volume takes 1% of the axis. In $d = 10$ dimensions it takes $0.01^{1/10} \approx 0.63$, so 63% of the range of every feature, and in $d = 100$ dimensions 95%. A neighbourhood that sees any reasonable share of the data stops being local, and methods that rely on nearby examples lose their footing. Filling space directly is hopeless too: covering each axis with just 10 bins already produces $10^d$ cells, so the sample size needed to populate them grows exponentially with $d$.
203
204
![The curse of dimensionality](/en/Machine%20Learning/02%20General%20concepts/a/curse-dimensionality.png)
205
206
*The edge length needed to capture a fixed fraction of the volume shoots toward 1 as the dimension grows: in high dimension, a "local" neighbourhood spans most of every axis.*
207
208
Two more symptoms follow from the same geometry. Almost all of the volume of a high-dimensional cube sits near its boundary, so a typical point has no interior around it. And pairwise distances concentrate: the nearest and the farthest neighbour end up almost equally far, so distance itself becomes less informative.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
209
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
210
*Remark:* this is why learning in high dimension leans on structure rather than raw proximity: linear models, regularization pulling toward simple fits, and features or embeddings that compress the inputs. Real data usually concentrates near a much lower-dimensional structure, and that is what makes learning possible at all.
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
211
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
212
*The concepts are in place: fitting minimizes a loss, generalizing is the goal, validation measures it, and regularization with hyperparameter tuning controls it. The next module builds the probabilistic language (Bayes' rule, entropy, likelihood) behind the first concrete models.*
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
213
214
---
0ad9b6 lugonthier 2026-07-10 12:03:30
Remove "07 Regularization and high-dimensional inference" chapter and add "07 Support Vector Machines" and "08 Decision trees and ensemble methods" chapters with corresponding images.
215
Next: [Probabilistic formulation](/en/Machine%20Learning/03%20Probabilistic%20formulation) · [Course overview](/en/Machine%20Learning)