Commit 17beab
2026-07-02 16:43:49 lugonthier: Add French translations for Regularization, Support Vector Machines, and Decision Trees modules - Created "08 Regularization and high-dimensional inference.md" with detailed explanations on regularization techniques including ridge, lasso, and elastic net. - Added images for L1 and L2 geometry and regularization path. - Created "09 Support Vector Machines.md" covering SVM concepts, including margin, loss functions, kernels, and duality. - Added images for SVM margin and kernel decision boundaries. - Created "10 Decision trees and ensemble methods.md" explaining decision trees, random forests, and boosting techniques. - Added images for decision tree boundaries and forest vs tree comparison.| en/Machine Learning.md .. | |
| @@ 12,9 12,10 @@ | |
| 4. [Probabilistic formulation](/en/Machine%20Learning/04%20Probabilistic%20formulation) | |
| 5. [Linear regression](/en/Machine%20Learning/05%20Linear%20regression) | |
| 6. [Linear classification](/en/Machine%20Learning/06%20Linear%20classification) | |
| - | 7. [Regularization and high-dimensional inference](/en/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference) |
| - | 8. [Support Vector Machines](/en/Machine%20Learning/08%20Support%20Vector%20Machines) |
| - | 9. [Decision trees and ensemble methods](/en/Machine%20Learning/09%20Decision%20trees%20and%20ensemble%20methods) |
| + | 7. [Multilayer neural networks](/en/Machine%20Learning/07%20Multilayer%20neural%20networks) |
| + | 8. [Regularization and high-dimensional inference](/en/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference) |
| + | 9. [Support Vector Machines](/en/Machine%20Learning/09%20Support%20Vector%20Machines) |
| + | 10. [Decision trees and ensemble methods](/en/Machine%20Learning/10%20Decision%20trees%20and%20ensemble%20methods) |
| --- | |
| [MLOps](/en/MLOps) · [Home](/en) | |
| en/Machine Learning/05 Linear regression.md .. | |
| @@ 54,7 54,7 @@ | |
| This is regularized (ridge) regression: the Gaussian prior becomes an L2 penalty, exactly the prior-to-penalty link noted in the previous module. | |
| - | *Remark:* a stronger prior (small $\tau$) means a larger $\lambda$ and more shrinkage toward zero. With abundant data the likelihood dominates the prior and the maximum-a-posteriori fit approaches the maximum-likelihood one. Choosing the degree $d$ and the penalty $\lambda$ is a model-selection problem, settled by cross-validation from the [evaluation module](/en/Machine%20Learning/03%20Model%20evaluation%20and%20validation), and taken further in the [regularization module](/en/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference). |
| + | *Remark:* a stronger prior (small $\tau$) means a larger $\lambda$ and more shrinkage toward zero. With abundant data the likelihood dominates the prior and the maximum-a-posteriori fit approaches the maximum-likelihood one. Choosing the degree $d$ and the penalty $\lambda$ is a model-selection problem, settled by cross-validation from the [evaluation module](/en/Machine%20Learning/03%20Model%20evaluation%20and%20validation), and taken further in the [regularization module](/en/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference). |
| *The same linear score, passed through a squashing function instead of read directly, turns regression into classification, the subject of the next module.* | |
| en/Machine Learning/06 Linear classification.md .. | |
| @@ 80,4 80,4 @@ | |
| *With linear models covered, the next module controls their complexity: regularization and inference when the regressors are many.* | |
| --- | |
| - | Next: [Regularization and high-dimensional inference](/en/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference) · [Course overview](/en/Machine%20Learning) |
| + | Next: [Multilayer neural networks](/en/Machine%20Learning/07%20Multilayer%20neural%20networks) · [Course overview](/en/Machine%20Learning) |
| /dev/null .. en/Machine Learning/07 Multilayer neural networks.md | |
| @@ 0,0 1,83 @@ | |
| + | # 7. Multilayer neural networks |
| + | |
| + | A single linear unit only draws a straight boundary. Stacking many simple units with a nonlinearity between them gives a multilayer neural network, which fits curved boundaries and learns its own features. This module is a compact tour of neural networks, from architecture to training, and the gateway to the [Deep Learning](/en/Deep%20Learning) course, which develops every topic here in depth. |
| + | |
| + | **Objectives** |
| + | - Contrast the linear and nonlinear approaches and see why hidden layers are needed. |
| + | - Read a network as input, hidden, and output layers, and write its forward pass. |
| + | - Choose the output layer and loss for binary and multiclass classification. |
| + | - Pick an activation function and see why zero-centered outputs help. |
| + | - Train by the chain rule and backpropagation, with mini-batches, good initialization, and dropout. |
| + | - Guard the implementation with gradient checking and vectorization. |
| + | |
| + | ## 7.1 Linear versus nonlinear |
| + | |
| + | The linear classifiers of the [previous module](/en/Machine%20Learning/06%20Linear%20classification) separate classes with a single straight boundary, so a problem like XOR, which is not linearly separable, is out of reach. Composing units through a nonlinear activation $g$ bends the boundary. The nonlinearity is essential: without it, a stack of linear layers collapses back to a single linear map, |
| + | |
| + | $$\boxed{ W^{[2]}\!\left(W^{[1]} x + b^{[1]}\right) + b^{[2]} = W' x + b' }$$ |
| + | |
| + | so depth would add nothing. The nonlinear activation is what makes stacking worthwhile. |
| + | |
| + | ## 7.2 Layers: input, hidden, output |
| + | |
| + | A single neuron computes $a = g(w^T x + b)$. A layer stacks many neurons, and a network stacks layers. Layer $l$ transforms the previous activations into new ones: |
| + | |
| + | $$\boxed{ z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}, \quad a^{[l]} = g^{[l]}\!\left(z^{[l]}\right), \quad a^{[0]} = x, \quad \hat{y} = a^{[L]} }$$ |
| + | |
| + | The input layer holds $x$, the hidden layers learn intermediate features, and the output layer produces the prediction $\hat{y}$. |
| + | |
| + |  |
| + | |
| + | *Each edge carries a weight in $W^{[l]}$ and each unit adds a bias then applies the activation.* |
| + | |
| + | *Remark:* the bias is now written out explicitly and each layer has its own weight matrix $W^{[l]}$, unlike the earlier convention of folding the bias into $\theta^T x$ with $x_0 = 1$. This is the notation the Deep Learning course uses throughout. |
| + | |
| + | ## 7.3 Output layer: binary and multiclass |
| + | |
| + | The output layer matches the task, reusing the losses from the previous module. For two classes, a sigmoid output with the binary cross-entropy; for $k$ classes, a softmax output with the categorical cross-entropy: |
| + | |
| + | $$\boxed{ \hat{y} = \frac{1}{1 + e^{-z}} \quad\text{(binary)} \qquad \hat{y}_c = \frac{e^{z_c}}{\sum_{j} e^{z_j}} \quad\text{(multiclass)} }$$ |
| + | |
| + | ## 7.4 Activation functions and the zero-centered problem |
| + | |
| + | The hidden activation is usually the sigmoid, the hyperbolic tangent, or the rectified linear unit: |
| + | |
| + | $$\boxed{ \sigma(z) = \frac{1}{1 + e^{-z}}, \qquad \tanh(z), \qquad \mathrm{ReLU}(z) = \max(0, z) }$$ |
| + | |
| + | The sigmoid saturates in its tails, and its outputs are never negative, so a unit's incoming weights all receive gradients of the same sign and the updates zig-zag. The zero-centered $\tanh$ removes that bias, and ReLU avoids positive-side saturation altogether, which is why it is the common default. |
| + | |
| + |  |
| + | |
| + | *The tanh is zero-centered while the sigmoid is not, and ReLU stays linear for positive inputs.* |
| + | |
| + | ## 7.5 Chain rule and backpropagation |
| + | |
| + | Training minimizes the loss by gradient descent, which needs its gradient with respect to every weight. Backpropagation computes all of them in one forward and one backward sweep: the forward pass caches each $z^{[l]}$ and $a^{[l]}$, then the backward pass applies the chain rule from the loss back to the first layer, reusing the cache. With the layer error $\delta^{[l]} = \partial L / \partial z^{[l]}$, |
| + | |
| + | $$\boxed{ \delta^{[l]} = \left((W^{[l+1]})^T \delta^{[l+1]}\right) \odot g'^{[l]}\!\left(z^{[l]}\right), \qquad \frac{\partial L}{\partial W^{[l]}} = \delta^{[l]} (a^{[l-1]})^T }$$ |
| + | |
| + |  |
| + | |
| + | *The [Backpropagation](/en/Deep%20Learning/05%20Backpropagation) lesson of the Deep Learning course derives this step by step.* |
| + | |
| + | ## 7.6 Training in practice |
| + | |
| + | - **Mini-batches.** Estimate the gradient on a small batch of examples at a time, a middle ground between the full batch (accurate but slow) and one example (noisy but cheap). |
| + | - **Vanishing gradient.** Through many saturating layers the backpropagated gradient is a product of small factors and shrinks toward zero, so early layers barely learn. ReLU activations and careful initialization keep it alive. |
| + | - **Initialization.** Start the weights small and random to break symmetry, scaling the variance by the number of inputs (Xavier or He), so signals neither vanish nor explode through depth. |
| + | - **Dropout.** Randomly zero a fraction of units during training. This prevents units from co-adapting and acts as a regularizer, one of the topics of the [next module](/en/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference). |
| + | |
| + | ## 7.7 Sanity checks and vectorization |
| + | |
| + | Backpropagation is error-prone, so check the analytic gradient against a numerical finite-difference estimate: |
| + | |
| + | $$\boxed{ \frac{\partial L}{\partial \theta} \approx \frac{L(\theta + \varepsilon) - L(\theta - \varepsilon)}{2\varepsilon} }$$ |
| + | |
| + | and implement the passes in vectorized form, one matrix operation per layer over the whole mini-batch (columns are examples), which is both clearer and far faster: |
| + | |
| + | $$\boxed{ Z^{[l]} = W^{[l]} A^{[l-1]} + b^{[l]} }$$ |
| + | |
| + | *This module is the doorway to the [Deep Learning](/en/Deep%20Learning) course, which develops architectures, optimizers, initialization, normalization, and regularization in full. The next module returns to the linear setting to control model complexity.* |
| + | |
| + | --- |
| + | Next: [Regularization and high-dimensional inference](/en/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference) · [Course overview](/en/Machine%20Learning) |
| /dev/null .. en/Machine Learning/07 Multilayer neural networks/activations.png | |
| /dev/null .. en/Machine Learning/07 Multilayer neural networks/backprop.svg | |
| @@ 0,0 1,1 @@ | |
| + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 240" width="900" height="240" font-family="Helvetica, Arial, sans-serif"><defs><marker id="arrow" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#1f2933"/></marker><marker id="arrowmuted" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#5b6b7b"/></marker></defs><rect width="900" height="240" fill="#ffffff"/><text x="450.0" y="22.0" font-family="Helvetica, Arial, sans-serif" font-size="15" font-weight="600" fill="#1f2933" text-anchor="middle">Backpropagation: a forward pass, then the chain rule backward</text><rect x="40.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><text x="88.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">x</text><rect x="180.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><text x="228.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">z<tspan baseline-shift="super" font-size="9px">[1]</tspan></text><line x1="136.0" y1="92.0" x2="180.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="320.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e7f5ea" stroke="#38a05a" stroke-width="1.6"/><text x="368.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">a<tspan baseline-shift="super" font-size="9px">[1]</tspan></text><line x1="276.0" y1="92.0" x2="320.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="460.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><text x="508.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">z<tspan baseline-shift="super" font-size="9px">[2]</tspan></text><line x1="416.0" y1="92.0" x2="460.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="600.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><text x="648.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">ŷ</text><line x1="556.0" y1="92.0" x2="600.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="740.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#fdecec" stroke="#d1495b" stroke-width="1.6"/><text x="788.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">loss L</text><line x1="696.0" y1="92.0" x2="740.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><text x="470.0" y="58.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">forward pass (solid): compute and cache</text><line x1="788.0" y1="148.0" x2="648.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="648.0" y1="148.0" x2="508.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="508.0" y1="148.0" x2="368.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="368.0" y1="148.0" x2="228.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="228.0" y1="148.0" x2="88.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><text x="470.0" y="170.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">backward pass (dashed): propagate the error by the chain rule</text></svg> |
| \ | No newline at end of file |
| /dev/null .. en/Machine Learning/07 Multilayer neural networks/mlp-layers.svg | |
| @@ 0,0 1,1 @@ | |
| + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 740 347" width="740" height="347" font-family="Helvetica, Arial, sans-serif"><defs><marker id="arrow" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#1f2933"/></marker><marker id="arrowmuted" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#5b6b7b"/></marker></defs><rect width="740" height="347" fill="#ffffff"/><text x="370.0" y="22.0" font-family="Helvetica, Arial, sans-serif" font-size="15" font-weight="600" fill="#1f2933" text-anchor="middle">A network: input, hidden, and output layers</text><line x1="125.0" y1="131.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="87.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="87.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="131.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="131.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="175.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="175.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="219.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="219.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="263.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="263.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><circle cx="110.0" cy="131.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="110.0" cy="175.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="110.0" cy="219.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="280.0" cy="87.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="131.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="175.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="219.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="263.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="87.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="131.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="175.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="219.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="263.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="620.0" cy="153.0" r="15.0" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><circle cx="620.0" cy="197.0" r="15.0" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><text x="110.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">input layer</text><text x="280.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">hidden layer</text><text x="450.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">hidden layer</text><text x="620.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">output layer</text><text x="370.0" y="326.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">each unit computes a<tspan baseline-shift="super" font-size="9px">[l]</tspan> = g(W<tspan baseline-shift="super" font-size="9px">[l]</tspan> a<tspan baseline-shift="super" font-size="9px">[l-1]</tspan> + b<tspan baseline-shift="super" font-size="9px">[l]</tspan>)</text></svg> |
| \ | No newline at end of file |
| en/Machine Learning/07 Regularization and high-dimensional inference.md .. en/Machine Learning/08 Regularization and high-dimensional inference.md | |
| @@ 1,4 1,4 @@ | |
| - | # 7. Regularization and high-dimensional inference |
| + | # 8. Regularization and high-dimensional inference |
| 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. | |
| @@ 11,11 11,11 @@ | |
| - Choose the penalty $\lambda$ by cross-validation. | |
| - Recognize why naive post-selection inference is invalid, and know the standard corrections. | |
| - | ## 7.1 Why regularize |
| + | ## 8.1 Why regularize |
| 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). | |
| - | ## 7.2 Ridge regression (L2) |
| + | ## 8.2 Ridge regression (L2) |
| Ridge adds a squared-norm penalty on the coefficients to the least-squares objective: | |
| @@ 27,7 27,7 @@ | |
| Ridge shrinks all coefficients smoothly toward zero but never sets them exactly to zero, so it stabilizes rather than selects. | |
| - | ## 7.3 Lasso regression (L1) |
| + | ## 8.3 Lasso regression (L1) |
| The lasso replaces the squared penalty with an absolute-value penalty: | |
| @@ 35,17 35,17 @@ | |
| 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. | |
| - |  |
| + |  |
| *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.* | |
| As the penalty grows, more coefficients cross to zero, tracing the regularization path from the full model to the empty one. | |
| - |  |
| + |  |
| *Each coefficient shrinks as $\lambda$ increases and then hits exactly zero, so the lasso yields a compact, interpretable subset of regressors.* | |
| - | ## 7.4 Elastic net |
| + | ## 8.4 Elastic net |
| The elastic net blends the two penalties, keeping the lasso's selection while borrowing the ridge's stability with correlated regressors: | |
| @@ 53,11 53,11 @@ | |
| with $\alpha \in [0, 1]$ mixing selection ($\alpha = 1$, lasso) and shrinkage ($\alpha = 0$, ridge). | |
| - | ## 7.5 Choosing the penalty |
| + | ## 8.5 Choosing the penalty |
| 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. | |
| - | ## 7.6 The inference caveat |
| + | ## 8.6 The inference caveat |
| 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: | |
| @@ 72,4 72,4 @@ | |
| *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.* | |
| --- | |
| - | Next: [Support Vector Machines](/en/Machine%20Learning/08%20Support%20Vector%20Machines) · [Course overview](/en/Machine%20Learning) |
| + | Next: [Support Vector Machines](/en/Machine%20Learning/09%20Support%20Vector%20Machines) · [Course overview](/en/Machine%20Learning) |
| en/Machine Learning/07 Regularization and high-dimensional inference/l1-l2-geometry.png .. en/Machine Learning/08 Regularization and high-dimensional inference/l1-l2-geometry.png | |
| en/Machine Learning/07 Regularization and high-dimensional inference/regularization-path.png .. en/Machine Learning/08 Regularization and high-dimensional inference/regularization-path.png | |
| en/Machine Learning/08 Support Vector Machines.md .. en/Machine Learning/09 Support Vector Machines.md | |
| @@ 1,4 1,4 @@ | |
| - | # 8. Support Vector Machines |
| + | # 9. Support Vector Machines |
| Support vector machines are large-margin linear classifiers. They pick the boundary that | |
| maximizes the distance to the nearest points, control overfitting with the hinge loss and a | |
| @@ 11,11 11,11 @@ | |
| - Define kernels, the kernel trick, and the Mercer condition. | |
| - Form the Lagrangian, derive the dual and KKT conditions, and define support vectors. | |
| - | ## 8.1 Optimal margin classifier |
| + | ## 9.1 Optimal margin classifier |
| Labels are $y \in \{-1,+1\}$, with weight vector $w \in \mathbb{R}^{n}$ and bias $b$. | |
| - | ### 8.1.1 Hypothesis and boundary |
| + | ### 9.1.1 Hypothesis and boundary |
| The hypothesis is defined as the sign of the raw score $z = w^T x - b$: | |
| @@ 27,7 27,7 @@ | |
| *Remark:* $w$ is orthogonal to the boundary, so it sets the orientation, and $b$ sets the offset. | |
| - | ### 8.1.2 Geometric margin |
| + | ### 9.1.2 Geometric margin |
| The geometric margin of example $i$ is defined as its signed distance to the boundary, made | |
| positive by the label: | |
| @@ 40,7 40,7 @@ | |
| *Remark:* dividing by $\lVert w \rVert$ makes the margin invariant to rescaling $(w,b)$, unlike | |
| the raw score $z$. | |
| - | ### 8.1.3 Hard-margin primal |
| + | ### 9.1.3 Hard-margin primal |
| Fixing the scale so the closest points satisfy $y^{(i)}(w^T x^{(i)} - b) = 1$, maximizing the | |
| margin is equivalent to minimizing $\lVert w \rVert^2$ subject to a unit functional margin: | |
| @@ 52,15 52,15 @@ | |
| *Remark:* it requires the data to be linearly separable. The next lesson relaxes that with slack | |
| variables. | |
| - |  |
| + |  |
| *The optimal hyperplane (solid) maximizes the margin (dashed). Circled points are the support vectors.* | |
| - | ## 8.2 Hinge loss |
| + | ## 9.2 Hinge loss |
| The raw score is $z = w^T x - b$ and labels are $y \in \{-1,+1\}$. | |
| - | ### 8.2.1 Hinge loss |
| + | ### 9.2.1 Hinge loss |
| The hinge loss is defined as the amount by which the margin $yz$ falls short of $1$, clipped at zero: | |
| @@ 72,7 72,7 @@ | |
| *Remark:* the hinge loss is convex but not differentiable at $yz = 1$, so it is optimized with | |
| subgradients. | |
| - | ### 8.2.2 Soft-margin primal |
| + | ### 9.2.2 Soft-margin primal |
| Introduce a slack $\xi_i \ge 0$ per example to allow margin violations, penalized by $C > 0$: | |
| @@ 86,7 86,7 @@ | |
| This is regularization plus hinge loss: the $\tfrac{1}{2}\lVert w \rVert^2$ term widens the margin | |
| and the sum penalizes violations. | |
| - | ### 8.2.3 Role of $C$ |
| + | ### 9.2.3 Role of $C$ |
| | $C$ | Penalty on violations | Margin | Behaviour | | |
| | --- | --- | --- | --- | | |
| @@ 95,9 95,9 @@ | |
| *Remark:* as $C \to \infty$ no violation is tolerated, which recovers the hard-margin classifier. | |
| - | ## 8.3 Kernels |
| + | ## 9.3 Kernels |
| - | ### 8.3.1 Kernel definition |
| + | ### 9.3.1 Kernel definition |
| A kernel is defined as the inner product of a feature map $\phi$ applied to two inputs: | |
| @@ 106,7 106,7 @@ | |
| A valid kernel computes this inner product directly, so $\phi$ never has to be formed (it may even | |
| be infinite-dimensional). | |
| - | ### 8.3.2 Kernel trick |
| + | ### 9.3.2 Kernel trick |
| The SVM dual depends on the data only through inner products $\langle x^{(i)}, x^{(j)} \rangle$. | |
| The kernel trick replaces each inner product with a kernel: | |
| @@ 120,7 120,7 @@ | |
| $$\boxed{ K(x,z) = \exp\!\left( -\frac{\lVert x - z \rVert^2}{2\sigma^2} \right) }$$ | |
| - | ### 8.3.3 Mercer condition |
| + | ### 9.3.3 Mercer condition |
| A function $K$ is a valid kernel if and only if, for every finite sample, its Gram matrix is | |
| symmetric positive semidefinite: | |
| @@ 130,7 130,7 @@ | |
| *Remark:* this is the Mercer condition. It guarantees a feature map $\phi$ exists, so the dual stays | |
| convex. | |
| - | ### 8.3.4 Common kernels |
| + | ### 9.3.4 Common kernels |
| | Kernel | $K(x,z)$ | Note | | |
| | --- | --- | --- | | |
| @@ 141,13 141,13 @@ | |
| *Remark:* a small $\sigma$ makes the RBF kernel very local, which can overfit. It trades off against | |
| $C$. | |
| - |  |
| + |  |
| *An RBF kernel separates classes that are not linearly separable, with a nonlinear boundary in the input space.* | |
| - | ## 8.4 Lagrangian and duality |
| + | ## 9.4 Lagrangian and duality |
| - | ### 8.4.1 Lagrangian |
| + | ### 9.4.1 Lagrangian |
| For a primal objective $f(w)$ with inequality constraints $g_i(w) \le 0$ and multipliers | |
| $\beta_i \ge 0$, the Lagrangian is defined as: | |
| @@ 162,16 162,16 @@ | |
| So the optimal $w$ is a linear combination of the training inputs weighted by $\beta_i y^{(i)}$. | |
| - | ### 8.4.2 Dual problem |
| + | ### 9.4.2 Dual problem |
| Substituting these back eliminates $w$ and $b$, leaving a problem in $\beta$ that depends on the | |
| data only through inner products: | |
| $$\boxed{ \max_{\beta} \ \sum_{i=1}^{m}\beta_i - \tfrac{1}{2}\sum_{i,j}\beta_i \beta_j\, y^{(i)} y^{(j)} \langle x^{(i)}, x^{(j)} \rangle \quad \text{s.t.} \quad \beta_i \ge 0, \ \ \sum_{i}\beta_i y^{(i)} = 0 }$$ | |
| - | The inner products are exactly where a kernel $K$ is substituted (see [Kernels](/en/Machine%20Learning/08%20Support%20Vector%20Machines#83-kernels)). |
| + | The inner products are exactly where a kernel $K$ is substituted (see [Kernels](/en/Machine%20Learning/09%20Support%20Vector%20Machines#93-kernels)). |
| - | ### 8.4.3 KKT and support vectors |
| + | ### 9.4.3 KKT and support vectors |
| At the optimum, complementary slackness ties each multiplier to its constraint: | |
| @@ 183,7 183,7 @@ | |
| These are the points exactly on the margin. All others have $\beta_i = 0$ and do not affect $w$. | |
| - | ### 8.4.4 Kernelized decision |
| + | ### 9.4.4 Kernelized decision |
| Replacing the inner product by a kernel gives a decision rule expressed only through support vectors: | |
| @@ 192,7 192,7 @@ | |
| *Remark:* only support vectors ($\beta_i > 0$) contribute, so prediction cost scales with their | |
| count, not with $m$. | |
| - | ### 8.4.5 From primal to decision |
| + | ### 9.4.5 From primal to decision |
| ```mermaid | |
| flowchart TD | |
| @@ 212,4 212,4 @@ | |
| *Support vector machines draw a single, possibly kernelized, boundary. The final part takes a different route: split the feature space with simple rules and combine many such models into an ensemble.* | |
| --- | |
| - | Next: [Decision trees and ensemble methods](/en/Machine%20Learning/09%20Decision%20trees%20and%20ensemble%20methods) · [Course overview](/en/Machine%20Learning) |
| + | Next: [Decision trees and ensemble methods](/en/Machine%20Learning/10%20Decision%20trees%20and%20ensemble%20methods) · [Course overview](/en/Machine%20Learning) |
| en/Machine Learning/08 Support Vector Machines/svm-kernel.png .. en/Machine Learning/09 Support Vector Machines/svm-kernel.png | |
| en/Machine Learning/08 Support Vector Machines/svm-margin.png .. en/Machine Learning/09 Support Vector Machines/svm-margin.png | |
| en/Machine Learning/09 Decision trees and ensemble methods.md .. en/Machine Learning/10 Decision trees and ensemble methods.md | |
| @@ 1,4 1,4 @@ | |
| - | # 9. Decision trees and ensemble methods |
| + | # 10. Decision trees and ensemble methods |
| Tree models partition the input space into axis-aligned regions and fit a constant per region, giving interpretable but high-variance predictors. Ensemble methods combine many trees: bagging and random forests average independently grown trees to cut variance, while boosting grows trees sequentially to cut bias. | |
| @@ 9,9 9,9 @@ | |
| - Estimate generalization error for free with out-of-bag samples. | |
| - Build a strong predictor as an additive sum of weak learners (AdaBoost, gradient boosting). | |
| - | ## 9.1 CART decision trees |
| + | ## 10.1 CART decision trees |
| - | ### 9.1.1 Tree as a partition |
| + | ### 10.1.1 Tree as a partition |
| A CART tree partitions the input space into $M$ disjoint regions $R_1,\dots,R_M$ (the leaves) and predicts a constant $c_m$ on each. The prediction is defined as | |
| @@ 21,7 21,7 @@ | |
| *Remark:* the regions are axis-aligned boxes, so the decision boundary is a staircase. A single tree has low bias but high variance. | |
| - | ### 9.1.2 Impurity and split selection |
| + | ### 10.1.2 Impurity and split selection |
| For a region with class proportions $\hat p_k$, impurity measures how mixed the labels are. The Gini index is defined as | |
| @@ 44,7 44,7 @@ | |
| *Remark:* the two criteria almost always pick the same split. Gini is the default in most implementations because it avoids the logarithm. | |
| - | ### 9.1.3 Regression trees |
| + | ### 10.1.3 Regression trees |
| For regression the leaf value is the mean of the targets in the region, defined as | |
| @@ 52,7 52,7 @@ | |
| and splits minimize the within-region squared error instead of a classification impurity. | |
| - | ### 9.1.4 Pruning |
| + | ### 10.1.4 Pruning |
| An unpruned tree fits the training set exactly and overfits. Cost-complexity pruning trades fit against tree size $|T|$ (the number of leaves) through a penalty $\alpha\ge0$: | |
| @@ 68,13 68,13 @@ | |
| B -->|"no"| E["leaf R2"] | |
| ``` | |
| - |  |
| + |  |
| *A tree carves the input space into axis-aligned regions, each with a constant prediction.* | |
| - | ## 9.2 Random forests |
| + | ## 10.2 Random forests |
| - | ### 9.2.1 Bagging |
| + | ### 10.2.1 Bagging |
| Bagging (bootstrap aggregating) trains $B$ trees on $B$ bootstrap resamples of the data and averages them. The bagged predictor is defined as | |
| @@ 84,7 84,7 @@ | |
| A bootstrap sample draws $N$ examples with replacement from $N$ examples. The probability that a given example is never drawn is $(1-\tfrac1N)^N\to e^{-1}\approx0.37$, so about 37% of the data is left out of each tree. These are its out-of-bag (OOB) examples. | |
| - | ### 9.2.2 Variance of an average |
| + | ### 10.2.2 Variance of an average |
| If the $B$ trees each have variance $\sigma^2$ and pairwise correlation $\rho$, the variance of their average is | |
| @@ 92,7 92,7 @@ | |
| The second term vanishes as $B$ grows, but the first, $\rho\sigma^2$, does not. Reducing the correlation $\rho$ between trees is therefore the key lever, and that is what random forests target. | |
| - | ### 9.2.3 Random forests |
| + | ### 10.2.3 Random forests |
| A random forest is bagging plus feature subsampling: at each split only a random subset of $m_{\text{try}}$ features is considered as split candidates. The usual choices are | |
| @@ 122,13 122,13 @@ | |
| T3 --> AGG | |
| ``` | |
| - |  |
| + |  |
| *(a) A single deep tree overfits with a jagged boundary. (b) A random forest averages many trees for a smoother boundary.* | |
| - | ## 9.3 Boosting |
| + | ## 10.3 Boosting |
| - | ### 9.3.1 Additive model |
| + | ### 10.3.1 Additive model |
| Boosting builds a predictor as a weighted sum of $T$ weak learners $h_t$ (typically shallow trees), fitted one at a time. The additive model is defined as | |
| @@ 136,7 136,7 @@ | |
| Each stage corrects the errors of the running sum, so the ensemble is built sequentially and reduces bias rather than variance. | |
| - | ### 9.3.2 AdaBoost |
| + | ### 10.3.2 AdaBoost |
| With labels $y\in\{-1,+1\}$, AdaBoost keeps example weights $w^{(i)}$ that concentrate on the currently misclassified points. At round $t$ the weak learner has weighted error $\varepsilon_t$, and its coefficient is defined as | |
| @@ 148,7 148,7 @@ | |
| and renormalized. Misclassified examples ($y^{(i)}h_t(x^{(i)})<0$) gain weight, so the next learner focuses on them. | |
| - | ### 9.3.3 Gradient boosting |
| + | ### 10.3.3 Gradient boosting |
| Gradient boosting generalizes the idea to any differentiable loss $L$. At stage $t$ it fits the next learner to the negative gradient of the loss evaluated at the current model, the pseudo-residual defined as | |
| en/Machine Learning/09 Decision trees and ensemble methods/forest-vs-tree.png .. en/Machine Learning/10 Decision trees and ensemble methods/forest-vs-tree.png | |
| en/Machine Learning/09 Decision trees and ensemble methods/tree-boundary.png .. en/Machine Learning/10 Decision trees and ensemble methods/tree-boundary.png | |
| fr/Machine Learning.md .. | |
| @@ 12,9 12,10 @@ | |
| 4. [Formulation probabiliste](/fr/Machine%20Learning/04%20Probabilistic%20formulation) | |
| 5. [Régression linéaire](/fr/Machine%20Learning/05%20Linear%20regression) | |
| 6. [Classification linéaire](/fr/Machine%20Learning/06%20Linear%20classification) | |
| - | 7. [Régularisation et inférence en grande dimension](/fr/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference) |
| - | 8. [Machines à vecteurs de support](/fr/Machine%20Learning/08%20Support%20Vector%20Machines) |
| - | 9. [Arbres de décision et méthodes d'ensemble](/fr/Machine%20Learning/09%20Decision%20trees%20and%20ensemble%20methods) |
| + | 7. [Réseaux de neurones multi-couches](/fr/Machine%20Learning/07%20Multilayer%20neural%20networks) |
| + | 8. [Régularisation et inférence en grande dimension](/fr/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference) |
| + | 9. [Machines à vecteurs de support](/fr/Machine%20Learning/09%20Support%20Vector%20Machines) |
| + | 10. [Arbres de décision et méthodes d'ensemble](/fr/Machine%20Learning/10%20Decision%20trees%20and%20ensemble%20methods) |
| --- | |
| [MLOps](/fr/MLOps) · [Accueil](/fr) | |
| fr/Machine Learning/05 Linear regression.md .. | |
| @@ 54,7 54,7 @@ | |
| C'est la régression régularisée (ridge) : l'a priori gaussien devient une pénalité L2, exactement le lien a priori vers pénalité noté au module précédent. | |
| - | *Remarque :* un a priori plus fort (petit $\tau$) signifie un $\lambda$ plus grand et un rétrécissement plus marqué vers zéro. Avec beaucoup de données, la vraisemblance domine l'a priori et l'ajustement du maximum a posteriori se rapproche de celui du maximum de vraisemblance. Choisir le degré $d$ et la pénalité $\lambda$ est un problème de sélection de modèle, réglé par la validation croisée du [module d'évaluation](/fr/Machine%20Learning/03%20Model%20evaluation%20and%20validation), et approfondi dans le [module de régularisation](/fr/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference). |
| + | *Remarque :* un a priori plus fort (petit $\tau$) signifie un $\lambda$ plus grand et un rétrécissement plus marqué vers zéro. Avec beaucoup de données, la vraisemblance domine l'a priori et l'ajustement du maximum a posteriori se rapproche de celui du maximum de vraisemblance. Choisir le degré $d$ et la pénalité $\lambda$ est un problème de sélection de modèle, réglé par la validation croisée du [module d'évaluation](/fr/Machine%20Learning/03%20Model%20evaluation%20and%20validation), et approfondi dans le [module de régularisation](/fr/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference). |
| *Le même score linéaire, passé dans une fonction de compression au lieu d'être lu directement, transforme la régression en classification, le sujet du module suivant.* | |
| fr/Machine Learning/06 Linear classification.md .. | |
| @@ 80,4 80,4 @@ | |
| *Les modèles linéaires étant couverts, le module suivant contrôle leur complexité : la régularisation et l'inférence quand les régresseurs sont nombreux.* | |
| --- | |
| - | Suivant : [Régularisation et inférence en grande dimension](/fr/Machine%20Learning/07%20Regularization%20and%20high-dimensional%20inference) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| + | Suivant : [Réseaux de neurones multi-couches](/fr/Machine%20Learning/07%20Multilayer%20neural%20networks) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| /dev/null .. fr/Machine Learning/07 Multilayer neural networks.md | |
| @@ 0,0 1,83 @@ | |
| + | # 7. Réseaux de neurones multi-couches |
| + | |
| + | Une seule unité linéaire ne trace qu'une frontière droite. Empiler de nombreuses unités simples avec une non-linéarité entre elles donne un réseau de neurones multi-couches, qui ajuste des frontières courbes et apprend ses propres caractéristiques. Ce module est un tour d'horizon compact des réseaux de neurones, de l'architecture à l'entraînement, et la porte d'entrée du cours de [Deep Learning](/fr/Deep%20Learning), qui développe en profondeur chaque sujet abordé ici. |
| + | |
| + | **Objectifs** |
| + | - Opposer les approches linéaire et non linéaire et voir pourquoi les couches cachées sont nécessaires. |
| + | - Lire un réseau comme des couches d'entrée, cachées et de sortie, et écrire sa passe avant. |
| + | - Choisir la couche de sortie et la perte pour la classification binaire et multiclasse. |
| + | - Choisir une fonction d'activation et voir pourquoi des sorties centrées en zéro aident. |
| + | - Entraîner par la règle de dérivation en chaîne et la rétropropagation, avec des mini-lots, une bonne initialisation et le dropout. |
| + | - Protéger l'implémentation par la vérification du gradient et la vectorisation. |
| + | |
| + | ## 7.1 Linéaire contre non linéaire |
| + | |
| + | Les classifieurs linéaires du [module précédent](/fr/Machine%20Learning/06%20Linear%20classification) séparent les classes par une seule frontière droite, si bien qu'un problème comme XOR, non linéairement séparable, est hors de portée. Composer des unités à travers une activation non linéaire $g$ courbe la frontière. La non-linéarité est essentielle : sans elle, une pile de couches linéaires se réduit à une seule application linéaire, |
| + | |
| + | $$\boxed{ W^{[2]}\!\left(W^{[1]} x + b^{[1]}\right) + b^{[2]} = W' x + b' }$$ |
| + | |
| + | et la profondeur n'apporterait rien. C'est l'activation non linéaire qui rend l'empilement utile. |
| + | |
| + | ## 7.2 Les couches : entrée, cachée, sortie |
| + | |
| + | Un neurone calcule $a = g(w^T x + b)$. Une couche empile plusieurs neurones, et un réseau empile des couches. La couche $l$ transforme les activations précédentes en nouvelles : |
| + | |
| + | $$\boxed{ z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}, \quad a^{[l]} = g^{[l]}\!\left(z^{[l]}\right), \quad a^{[0]} = x, \quad \hat{y} = a^{[L]} }$$ |
| + | |
| + | La couche d'entrée contient $x$, les couches cachées apprennent des caractéristiques intermédiaires, et la couche de sortie produit la prédiction $\hat{y}$. |
| + | |
| + |  |
| + | |
| + | *Chaque arête porte un poids de $W^{[l]}$ et chaque unité ajoute un biais puis applique l'activation.* |
| + | |
| + | *Remarque :* le biais est désormais écrit explicitement et chaque couche a sa propre matrice de poids $W^{[l]}$, contrairement à la convention antérieure qui repliait le biais dans $\theta^T x$ avec $x_0 = 1$. C'est la notation utilisée tout au long du cours de Deep Learning. |
| + | |
| + | ## 7.3 Couche de sortie : binaire et multiclasse |
| + | |
| + | La couche de sortie s'adapte à la tâche, en réutilisant les pertes du module précédent. Pour deux classes, une sortie sigmoïde avec l'entropie croisée binaire ; pour $k$ classes, une sortie softmax avec l'entropie croisée catégorielle : |
| + | |
| + | $$\boxed{ \hat{y} = \frac{1}{1 + e^{-z}} \quad\text{(binaire)} \qquad \hat{y}_c = \frac{e^{z_c}}{\sum_{j} e^{z_j}} \quad\text{(multiclasse)} }$$ |
| + | |
| + | ## 7.4 Fonctions d'activation et le problème du non-centrage en zéro |
| + | |
| + | L'activation cachée est généralement la sigmoïde, la tangente hyperbolique ou l'unité de rectification linéaire : |
| + | |
| + | $$\boxed{ \sigma(z) = \frac{1}{1 + e^{-z}}, \qquad \tanh(z), \qquad \mathrm{ReLU}(z) = \max(0, z) }$$ |
| + | |
| + | La sigmoïde sature dans ses queues, et ses sorties ne sont jamais négatives, donc les poids entrants d'une unité reçoivent des gradients de même signe et les mises à jour zigzaguent. La $\tanh$, centrée en zéro, supprime ce biais, et ReLU évite complètement la saturation du côté positif, ce qui en fait le choix par défaut courant. |
| + | |
| + |  |
| + | |
| + | *La tanh est centrée en zéro alors que la sigmoïde ne l'est pas, et ReLU reste linéaire pour les entrées positives.* |
| + | |
| + | ## 7.5 Règle de dérivation en chaîne et rétropropagation |
| + | |
| + | L'entraînement minimise la perte par descente de gradient, qui a besoin de son gradient par rapport à chaque poids. La rétropropagation les calcule tous en une passe avant et une passe arrière : la passe avant met en cache chaque $z^{[l]}$ et $a^{[l]}$, puis la passe arrière applique la règle de dérivation en chaîne de la perte jusqu'à la première couche, en réutilisant le cache. Avec l'erreur de couche $\delta^{[l]} = \partial L / \partial z^{[l]}$, |
| + | |
| + | $$\boxed{ \delta^{[l]} = \left((W^{[l+1]})^T \delta^{[l+1]}\right) \odot g'^{[l]}\!\left(z^{[l]}\right), \qquad \frac{\partial L}{\partial W^{[l]}} = \delta^{[l]} (a^{[l-1]})^T }$$ |
| + | |
| + |  |
| + | |
| + | *La leçon [Rétropropagation](/fr/Deep%20Learning/05%20Backpropagation) du cours de Deep Learning la dérive pas à pas.* |
| + | |
| + | ## 7.6 L'entraînement en pratique |
| + | |
| + | - **Mini-lots.** Estimer le gradient sur un petit lot d'exemples à la fois, un compromis entre le lot complet (précis mais lent) et un seul exemple (bruité mais peu coûteux). |
| + | - **Disparition du gradient.** À travers de nombreuses couches qui saturent, le gradient rétropropagé est un produit de petits facteurs et tend vers zéro, si bien que les premières couches n'apprennent presque pas. Les activations ReLU et une initialisation soignée le maintiennent vivant. |
| + | - **Initialisation.** Démarrer les poids petits et aléatoires pour briser la symétrie, en mettant la variance à l'échelle du nombre d'entrées (Xavier ou He), pour que les signaux ne s'évanouissent ni n'explosent avec la profondeur. |
| + | - **Dropout.** Mettre à zéro au hasard une fraction des unités pendant l'entraînement. Cela empêche les unités de se co-adapter et agit comme un régulariseur, l'un des sujets du [module suivant](/fr/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference). |
| + | |
| + | ## 7.7 Tests de validité et vectorisation |
| + | |
| + | La rétropropagation est source d'erreurs, alors on compare le gradient analytique à une estimation numérique par différences finies : |
| + | |
| + | $$\boxed{ \frac{\partial L}{\partial \theta} \approx \frac{L(\theta + \varepsilon) - L(\theta - \varepsilon)}{2\varepsilon} }$$ |
| + | |
| + | et on implémente les passes sous forme vectorisée, une opération matricielle par couche sur tout le mini-lot (les colonnes sont les exemples), ce qui est à la fois plus clair et bien plus rapide : |
| + | |
| + | $$\boxed{ Z^{[l]} = W^{[l]} A^{[l-1]} + b^{[l]} }$$ |
| + | |
| + | *Ce module est la porte d'entrée du cours de [Deep Learning](/fr/Deep%20Learning), qui développe pleinement les architectures, les optimiseurs, l'initialisation, la normalisation et la régularisation. Le module suivant revient au cadre linéaire pour contrôler la complexité du modèle.* |
| + | |
| + | --- |
| + | Suivant : [Régularisation et inférence en grande dimension](/fr/Machine%20Learning/08%20Regularization%20and%20high-dimensional%20inference) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| /dev/null .. fr/Machine Learning/07 Multilayer neural networks/activations.png | |
| /dev/null .. fr/Machine Learning/07 Multilayer neural networks/backprop.svg | |
| @@ 0,0 1,1 @@ | |
| + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 240" width="900" height="240" font-family="Helvetica, Arial, sans-serif"><defs><marker id="arrow" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#1f2933"/></marker><marker id="arrowmuted" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#5b6b7b"/></marker></defs><rect width="900" height="240" fill="#ffffff"/><text x="450.0" y="22.0" font-family="Helvetica, Arial, sans-serif" font-size="15" font-weight="600" fill="#1f2933" text-anchor="middle">Backpropagation: a forward pass, then the chain rule backward</text><rect x="40.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><text x="88.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">x</text><rect x="180.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><text x="228.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">z<tspan baseline-shift="super" font-size="9px">[1]</tspan></text><line x1="136.0" y1="92.0" x2="180.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="320.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e7f5ea" stroke="#38a05a" stroke-width="1.6"/><text x="368.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">a<tspan baseline-shift="super" font-size="9px">[1]</tspan></text><line x1="276.0" y1="92.0" x2="320.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="460.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><text x="508.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">z<tspan baseline-shift="super" font-size="9px">[2]</tspan></text><line x1="416.0" y1="92.0" x2="460.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="600.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><text x="648.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">ŷ</text><line x1="556.0" y1="92.0" x2="600.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><rect x="740.0" y="70.0" width="96.0" height="44.0" rx="8" fill="#fdecec" stroke="#d1495b" stroke-width="1.6"/><text x="788.0" y="96.4" font-family="Helvetica, Arial, sans-serif" font-size="13" fill="#1f2933" text-anchor="middle">loss L</text><line x1="696.0" y1="92.0" x2="740.0" y2="92.0" stroke="#1f2933" stroke-width="1.7" marker-end="url(#arrow)"/><text x="470.0" y="58.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">forward pass (solid): compute and cache</text><line x1="788.0" y1="148.0" x2="648.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="648.0" y1="148.0" x2="508.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="508.0" y1="148.0" x2="368.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="368.0" y1="148.0" x2="228.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><line x1="228.0" y1="148.0" x2="88.0" y2="148.0" stroke="#5b6b7b" stroke-width="1.7" marker-end="url(#arrowmuted)" stroke-dasharray="5 4"/><text x="470.0" y="170.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">backward pass (dashed): propagate the error by the chain rule</text></svg> |
| \ | No newline at end of file |
| /dev/null .. fr/Machine Learning/07 Multilayer neural networks/mlp-layers.svg | |
| @@ 0,0 1,1 @@ | |
| + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 740 347" width="740" height="347" font-family="Helvetica, Arial, sans-serif"><defs><marker id="arrow" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#1f2933"/></marker><marker id="arrowmuted" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="#5b6b7b"/></marker></defs><rect width="740" height="347" fill="#ffffff"/><text x="370.0" y="22.0" font-family="Helvetica, Arial, sans-serif" font-size="15" font-weight="600" fill="#1f2933" text-anchor="middle">A network: input, hidden, and output layers</text><line x1="125.0" y1="131.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="131.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="175.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="125.0" y1="219.0" x2="265.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="87.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="131.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="175.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="219.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="87.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="131.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="175.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="219.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="295.0" y1="263.0" x2="435.0" y2="263.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="87.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="87.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="131.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="131.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="175.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="175.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="219.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="219.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="263.0" x2="605.0" y2="153.0" stroke="#c7d0d9" stroke-width="0.8"/><line x1="465.0" y1="263.0" x2="605.0" y2="197.0" stroke="#c7d0d9" stroke-width="0.8"/><circle cx="110.0" cy="131.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="110.0" cy="175.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="110.0" cy="219.0" r="15.0" fill="#eef1f4" stroke="#9aa7b2" stroke-width="1.6"/><circle cx="280.0" cy="87.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="131.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="175.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="219.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="280.0" cy="263.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="87.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="131.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="175.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="219.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="450.0" cy="263.0" r="15.0" fill="#e8f0fe" stroke="#3b6fb6" stroke-width="1.6"/><circle cx="620.0" cy="153.0" r="15.0" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><circle cx="620.0" cy="197.0" r="15.0" fill="#fff1e0" stroke="#e0872e" stroke-width="1.6"/><text x="110.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">input layer</text><text x="280.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">hidden layer</text><text x="450.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">hidden layer</text><text x="620.0" y="300.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">output layer</text><text x="370.0" y="326.0" font-family="Helvetica, Arial, sans-serif" font-size="12" fill="#5b6b7b" text-anchor="middle">each unit computes a<tspan baseline-shift="super" font-size="9px">[l]</tspan> = g(W<tspan baseline-shift="super" font-size="9px">[l]</tspan> a<tspan baseline-shift="super" font-size="9px">[l-1]</tspan> + b<tspan baseline-shift="super" font-size="9px">[l]</tspan>)</text></svg> |
| \ | No newline at end of file |
| fr/Machine Learning/07 Regularization and high-dimensional inference.md .. fr/Machine Learning/08 Regularization and high-dimensional inference.md | |
| @@ 1,4 1,4 @@ | |
| - | # 7. Régularisation et inférence en grande dimension |
| + | # 8. Régularisation et inférence en grande dimension |
| On n'a souvent pas une poignée de régresseurs propres. Il peut y avoir de nombreux prédicteurs candidats, parfois plus que d'observations, et ils sont corrélés. Les moindres carrés ordinaires surapprennent ou s'effondrent dans ce régime. La régularisation les dompte en rétrécissant les coefficients, et c'est là que la régression régularisée rejoint le plus directement la statistique classique. Elle s'accompagne d'un avertissement : sélectionner des variables puis faire de l'inférence sur les mêmes données invalide les écarts-types classiques, ce qui compte dès que l'objectif est une estimation causale plutôt qu'une prédiction. | |
| @@ 11,11 11,11 @@ | |
| - Choisir la pénalité $\lambda$ par validation croisée. | |
| - Reconnaître pourquoi l'inférence naïve après sélection est invalide, et connaître les corrections standard. | |
| - | ## 7.1 Pourquoi régulariser |
| + | ## 8.1 Pourquoi régulariser |
| Quand le nombre de régresseurs $p$ est grand par rapport à la taille d'échantillon $n$, l'ajustement par moindres carrés poursuit le bruit et ses coefficients ont une variance énorme. Avec des régresseurs corrélés, la matrice $X^T X$ est presque singulière, donc de petites variations des données font osciller fortement les estimations, et quand $p > n$ elle est singulière et les MCO n'ont aucune solution unique. La régularisation accepte un peu de biais en échange d'une forte réduction de variance, le compromis vu dans [Concepts généraux](/fr/Machine%20Learning/02%20General%20concepts). | |
| - | ## 7.2 Régression ridge (L2) |
| + | ## 8.2 Régression ridge (L2) |
| Ridge ajoute une pénalité en norme au carré sur les coefficients à l'objectif des moindres carrés : | |
| @@ 27,7 27,7 @@ | |
| Ridge rétrécit tous les coefficients doucement vers zéro mais ne les annule jamais exactement, elle stabilise donc plutôt qu'elle ne sélectionne. | |
| - | ## 7.3 Régression lasso (L1) |
| + | ## 8.3 Régression lasso (L1) |
| Le lasso remplace la pénalité au carré par une pénalité en valeur absolue : | |
| @@ 35,17 35,17 @@ | |
| Ce petit changement a une grande conséquence : le lasso met certains coefficients exactement à zéro, il effectue donc une sélection de variables tout en ajustant. La raison est géométrique. La région de contrainte $\|\beta\|_1 \le t$ est un losange dont les coins sont sur les axes, et les contours elliptiques de la perte tendent à la toucher d'abord en un coin, où une coordonnée est nulle. | |
| - |  |
| + |  |
| *La boule L2 arrondie est touchée hors des axes, gardant chaque coefficient non nul, tandis que le losange L1 est touché en un coin, mettant un coefficient exactement à zéro.* | |
| À mesure que la pénalité grandit, davantage de coefficients passent à zéro, traçant le chemin de régularisation du modèle complet jusqu'au modèle vide. | |
| - |  |
| + |  |
| *Chaque coefficient rétrécit quand $\lambda$ augmente puis atteint exactement zéro, si bien que le lasso fournit un sous-ensemble compact et interprétable de régresseurs.* | |
| - | ## 7.4 Elastic net |
| + | ## 8.4 Elastic net |
| L'elastic net mêle les deux pénalités, gardant la sélection du lasso tout en empruntant la stabilité de ridge face aux régresseurs corrélés : | |
| @@ 53,11 53,11 @@ | |
| avec $\alpha \in [0, 1]$ dosant la sélection ($\alpha = 1$, lasso) et le rétrécissement ($\alpha = 0$, ridge). | |
| - | ## 7.5 Choisir la pénalité |
| + | ## 8.5 Choisir la pénalité |
| La pénalité $\lambda$ est un hyperparamètre, on la choisit donc par validation croisée, vue au [module précédent](/fr/Machine%20Learning/03%20Model%20evaluation%20and%20validation) : on ajuste sur une grille de valeurs de $\lambda$ et on garde celle dont l'erreur validée est la plus faible, ou le plus grand $\lambda$ à un écart-type du meilleur pour un modèle plus simple. Un $\lambda$ plus grand signifie plus de rétrécissement, plus de biais et moins de variance. | |
| - | ## 7.6 La mise en garde sur l'inférence |
| + | ## 8.6 La mise en garde sur l'inférence |
| Prédire n'est pas inférer, et c'est le point qu'il est facile de manquer. Supposons que vous sélectionniez des régresseurs par lasso, puis que vous fassiez des moindres carrés ordinaires sur le sous-ensemble retenu en rapportant les écarts-types des manuels. Ces écarts-types sont faux. Ils ignorent que les données ont déjà servi à choisir les variables, donc les intervalles de confiance sont trop étroits et les p-valeurs ne sont pas valides, une forme de la malédiction du vainqueur. Trois corrections sont standard : | |
| @@ 72,4 72,4 @@ | |
| *Une fois le rétrécissement et la sélection couverts, le module suivant emprunte une autre voie vers une bonne frontière de décision, le classifieur à marge maximale, avant d'aborder les arbres et les ensembles.* | |
| --- | |
| - | Suivant : [Machines à vecteurs de support](/fr/Machine%20Learning/08%20Support%20Vector%20Machines) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| + | Suivant : [Machines à vecteurs de support](/fr/Machine%20Learning/09%20Support%20Vector%20Machines) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| fr/Machine Learning/07 Regularization and high-dimensional inference/l1-l2-geometry.png .. fr/Machine Learning/08 Regularization and high-dimensional inference/l1-l2-geometry.png | |
| fr/Machine Learning/07 Regularization and high-dimensional inference/regularization-path.png .. fr/Machine Learning/08 Regularization and high-dimensional inference/regularization-path.png | |
| fr/Machine Learning/08 Support Vector Machines.md .. fr/Machine Learning/09 Support Vector Machines.md | |
| @@ 1,4 1,4 @@ | |
| - | # 8. Machines à vecteurs de support |
| + | # 9. Machines à vecteurs de support |
| Les machines à vecteurs de support sont des classifieurs linéaires à grande marge. Elles | |
| choisissent la frontière qui maximise la distance aux points les plus proches, contrôlent le | |
| @@ 12,11 12,11 @@ | |
| - Définir les noyaux, l'astuce du noyau et la condition de Mercer. | |
| - Former le lagrangien, dériver le dual et les conditions KKT, et définir les vecteurs de support. | |
| - | ## 8.1 Classifieur à marge optimale |
| + | ## 9.1 Classifieur à marge optimale |
| Les étiquettes valent $y \in \{-1,+1\}$, avec un vecteur de poids $w \in \mathbb{R}^{n}$ et un biais $b$. | |
| - | ### 8.1.1 Hypothèse et frontière |
| + | ### 9.1.1 Hypothèse et frontière |
| L'hypothèse est définie comme le signe du score brut $z = w^T x - b$ : | |
| @@ 28,7 28,7 @@ | |
| *Remarque :* $w$ est orthogonal à la frontière, il en fixe donc l'orientation, et $b$ fixe le décalage. | |
| - | ### 8.1.2 Marge géométrique |
| + | ### 9.1.2 Marge géométrique |
| La marge géométrique de l'exemple $i$ est définie comme sa distance signée à la frontière, rendue | |
| positive par l'étiquette : | |
| @@ 41,7 41,7 @@ | |
| *Remarque :* diviser par $\lVert w \rVert$ rend la marge invariante au rééchelonnement de $(w,b)$, | |
| contrairement au score brut $z$. | |
| - | ### 8.1.3 Primal à marge dure |
| + | ### 9.1.3 Primal à marge dure |
| En fixant l'échelle pour que les points les plus proches vérifient $y^{(i)}(w^T x^{(i)} - b) = 1$, | |
| maximiser la marge équivaut à minimiser $\lVert w \rVert^2$ sous une marge fonctionnelle unitaire : | |
| @@ 53,15 53,15 @@ | |
| *Remarque :* il exige des données linéairement séparables. La leçon suivante assouplit cela avec | |
| des variables d'écart. | |
| - |  |
| + |  |
| *L'hyperplan optimal (trait plein) maximise la marge (pointillés). Les points entourés sont les vecteurs de support.* | |
| - | ## 8.2 Perte charnière |
| + | ## 9.2 Perte charnière |
| Le score brut est $z = w^T x - b$ et les étiquettes valent $y \in \{-1,+1\}$. | |
| - | ### 8.2.1 Perte charnière |
| + | ### 9.2.1 Perte charnière |
| La perte charnière est définie comme l'écart par lequel la marge $yz$ tombe sous $1$, tronqué à zéro : | |
| @@ 73,7 73,7 @@ | |
| *Remarque :* la perte charnière est convexe mais non dérivable en $yz = 1$, on l'optimise donc | |
| avec des sous-gradients. | |
| - | ### 8.2.2 Primal à marge souple |
| + | ### 9.2.2 Primal à marge souple |
| On introduit un écart $\xi_i \ge 0$ par exemple pour autoriser les violations de marge, pénalisé | |
| par $C > 0$ : | |
| @@ 88,7 88,7 @@ | |
| C'est de la régularisation plus une perte charnière : le terme $\tfrac{1}{2}\lVert w \rVert^2$ | |
| élargit la marge et la somme pénalise les violations. | |
| - | ### 8.2.3 Rôle de $C$ |
| + | ### 9.2.3 Rôle de $C$ |
| | $C$ | Pénalité des violations | Marge | Comportement | | |
| | --- | --- | --- | --- | | |
| @@ 98,9 98,9 @@ | |
| *Remarque :* quand $C \to \infty$ aucune violation n'est tolérée, ce qui redonne le classifieur à | |
| marge dure. | |
| - | ## 8.3 Noyaux |
| + | ## 9.3 Noyaux |
| - | ### 8.3.1 Définition d'un noyau |
| + | ### 9.3.1 Définition d'un noyau |
| Un noyau est défini comme le produit scalaire d'une application de caractéristiques $\phi$ | |
| appliquée à deux entrées : | |
| @@ 110,7 110,7 @@ | |
| Un noyau valide calcule ce produit scalaire directement, donc $\phi$ n'a jamais à être formée | |
| (elle peut même être de dimension infinie). | |
| - | ### 8.3.2 Astuce du noyau |
| + | ### 9.3.2 Astuce du noyau |
| Le dual du SVM ne dépend des données qu'à travers des produits scalaires | |
| $\langle x^{(i)}, x^{(j)} \rangle$. L'astuce du noyau remplace chaque produit scalaire par un noyau : | |
| @@ 124,7 124,7 @@ | |
| $$\boxed{ K(x,z) = \exp\!\left( -\frac{\lVert x - z \rVert^2}{2\sigma^2} \right) }$$ | |
| - | ### 8.3.3 Condition de Mercer |
| + | ### 9.3.3 Condition de Mercer |
| Une fonction $K$ est un noyau valide si et seulement si, pour tout échantillon fini, sa matrice de | |
| Gram est symétrique semi-définie positive : | |
| @@ 134,7 134,7 @@ | |
| *Remarque :* c'est la condition de Mercer. Elle garantit l'existence d'une application $\phi$, donc | |
| le dual reste convexe. | |
| - | ### 8.3.4 Noyaux usuels |
| + | ### 9.3.4 Noyaux usuels |
| | Noyau | $K(x,z)$ | Note | | |
| | --- | --- | --- | | |
| @@ 145,13 145,13 @@ | |
| *Remarque :* un petit $\sigma$ rend le noyau RBF très local, ce qui peut surapprendre. Il se règle | |
| en compromis avec $C$. | |
| - |  |
| + |  |
| *Un noyau RBF sépare des classes non linéairement séparables, par une frontière non linéaire dans l'espace d'entrée.* | |
| - | ## 8.4 Lagrangien et dualité |
| + | ## 9.4 Lagrangien et dualité |
| - | ### 8.4.1 Lagrangien |
| + | ### 9.4.1 Lagrangien |
| Pour un objectif primal $f(w)$ avec contraintes d'inégalité $g_i(w) \le 0$ et multiplicateurs | |
| $\beta_i \ge 0$, le lagrangien est défini comme : | |
| @@ 167,16 167,16 @@ | |
| Le $w$ optimal est donc une combinaison linéaire des entrées d'apprentissage pondérées par | |
| $\beta_i y^{(i)}$. | |
| - | ### 8.4.2 Problème dual |
| + | ### 9.4.2 Problème dual |
| En réinjectant ces relations, on élimine $w$ et $b$, ce qui laisse un problème en $\beta$ ne | |
| dépendant des données qu'à travers des produits scalaires : | |
| $$\boxed{ \max_{\beta} \ \sum_{i=1}^{m}\beta_i - \tfrac{1}{2}\sum_{i,j}\beta_i \beta_j\, y^{(i)} y^{(j)} \langle x^{(i)}, x^{(j)} \rangle \quad \text{s.c.} \quad \beta_i \ge 0, \ \ \sum_{i}\beta_i y^{(i)} = 0 }$$ | |
| - | Les produits scalaires sont exactement l'endroit où l'on substitue un noyau $K$ (voir [Noyaux](/fr/Machine%20Learning/08%20Support%20Vector%20Machines#83-noyaux)). |
| + | Les produits scalaires sont exactement l'endroit où l'on substitue un noyau $K$ (voir [Noyaux](/fr/Machine%20Learning/09%20Support%20Vector%20Machines#93-noyaux)). |
| - | ### 8.4.3 KKT et vecteurs de support |
| + | ### 9.4.3 KKT et vecteurs de support |
| À l'optimum, l'écart complémentaire lie chaque multiplicateur à sa contrainte : | |
| @@ 189,7 189,7 @@ | |
| Ce sont les points exactement sur la marge. Tous les autres ont $\beta_i = 0$ et n'influencent pas | |
| $w$. | |
| - | ### 8.4.4 Décision à noyau |
| + | ### 9.4.4 Décision à noyau |
| Remplacer le produit scalaire par un noyau donne une règle de décision exprimée uniquement à | |
| travers les vecteurs de support : | |
| @@ 199,7 199,7 @@ | |
| *Remarque :* seuls les vecteurs de support ($\beta_i > 0$) contribuent, donc le coût de prédiction | |
| croît avec leur nombre, pas avec $m$. | |
| - | ### 8.4.5 Du primal à la décision |
| + | ### 9.4.5 Du primal à la décision |
| ```mermaid | |
| flowchart TD | |
| @@ 219,4 219,4 @@ | |
| *Les machines à vecteurs de support tracent une seule frontière, éventuellement à noyau. La dernière partie suit une autre voie : découper l'espace des variables par des règles simples et combiner de nombreux modèles en un ensemble.* | |
| --- | |
| - | Suivant : [Arbres de décision et méthodes d'ensemble](/fr/Machine%20Learning/09%20Decision%20trees%20and%20ensemble%20methods) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| + | Suivant : [Arbres de décision et méthodes d'ensemble](/fr/Machine%20Learning/10%20Decision%20trees%20and%20ensemble%20methods) · [Vue d'ensemble du cours](/fr/Machine%20Learning) |
| fr/Machine Learning/08 Support Vector Machines/svm-kernel.png .. fr/Machine Learning/09 Support Vector Machines/svm-kernel.png | |
| fr/Machine Learning/08 Support Vector Machines/svm-margin.png .. fr/Machine Learning/09 Support Vector Machines/svm-margin.png | |
| fr/Machine Learning/09 Decision trees and ensemble methods.md .. fr/Machine Learning/10 Decision trees and ensemble methods.md | |
| @@ 1,4 1,4 @@ | |
| - | # 9. Arbres de décision et méthodes d'ensemble |
| + | # 10. Arbres de décision et méthodes d'ensemble |
| Les modèles d'arbre partitionnent l'espace d'entrée en régions alignées sur les axes et ajustent une constante par région, ce qui donne des prédicteurs interprétables mais à forte variance. Les méthodes d'ensemble combinent plusieurs arbres : le bagging et les forêts aléatoires moyennent des arbres construits indépendamment pour réduire la variance, tandis que le boosting construit les arbres de façon séquentielle pour réduire le biais. | |
| @@ 9,9 9,9 @@ | |
| - Estimer gratuitement l'erreur de généralisation avec les échantillons hors-sac. | |
| - Construire un prédicteur fort comme somme additive d'apprenants faibles (AdaBoost, gradient boosting). | |
| - | ## 9.1 Arbres de décision CART |
| + | ## 10.1 Arbres de décision CART |
| - | ### 9.1.1 L'arbre comme partition |
| + | ### 10.1.1 L'arbre comme partition |
| Un arbre CART partitionne l'espace d'entrée en $M$ régions disjointes $R_1,\dots,R_M$ (les feuilles) et prédit une constante $c_m$ sur chacune. La prédiction est définie par | |
| @@ 21,7 21,7 @@ | |
| *Remarque :* les régions sont des boîtes alignées sur les axes, donc la frontière de décision est en escalier. Un arbre seul a un faible biais mais une forte variance. | |
| - | ### 9.1.2 Impureté et choix de la coupure |
| + | ### 10.1.2 Impureté et choix de la coupure |
| Pour une région de proportions de classes $\hat p_k$, l'impureté mesure le mélange des étiquettes. L'indice de Gini est défini par | |
| @@ 44,7 44,7 @@ | |
| *Remarque :* les deux critères choisissent presque toujours la même coupure. Gini est le défaut de la plupart des implémentations car il évite le logarithme. | |
| - | ### 9.1.3 Arbres de régression |
| + | ### 10.1.3 Arbres de régression |
| En régression, la valeur de la feuille est la moyenne des cibles dans la région, définie par | |
| @@ 52,7 52,7 @@ | |
| et les coupures minimisent l'erreur quadratique intra-région plutôt qu'une impureté de classification. | |
| - | ### 9.1.4 Élagage |
| + | ### 10.1.4 Élagage |
| Un arbre non élagué ajuste exactement l'ensemble d'entraînement et surapprend. L'élagage à complexité coûteuse arbitre entre l'ajustement et la taille de l'arbre $|T|$ (le nombre de feuilles) via une pénalité $\alpha\ge0$ : | |
| @@ 68,13 68,13 @@ | |
| B -->|"non"| E["feuille R2"] | |
| ``` | |
| - |  |
| + |  |
| *Un arbre découpe l'espace en régions alignées sur les axes, chacune à prédiction constante.* | |
| - | ## 9.2 Forêts aléatoires |
| + | ## 10.2 Forêts aléatoires |
| - | ### 9.2.1 Bagging |
| + | ### 10.2.1 Bagging |
| Le bagging (bootstrap aggregating) entraîne $B$ arbres sur $B$ rééchantillons bootstrap des données et les moyenne. Le prédicteur agrégé est défini par | |
| @@ 84,7 84,7 @@ | |
| Un échantillon bootstrap tire $N$ exemples avec remise parmi $N$ exemples. La probabilité qu'un exemple donné ne soit jamais tiré vaut $(1-\tfrac1N)^N\to e^{-1}\approx0{,}37$, donc environ 37 % des données restent hors de chaque arbre. Ce sont ses exemples hors-sac (OOB). | |
| - | ### 9.2.2 Variance d'une moyenne |
| + | ### 10.2.2 Variance d'une moyenne |
| Si les $B$ arbres ont chacun une variance $\sigma^2$ et une corrélation deux à deux $\rho$, la variance de leur moyenne vaut | |
| @@ 92,7 92,7 @@ | |
| Le second terme s'annule quand $B$ croît, mais le premier, $\rho\sigma^2$, persiste. Réduire la corrélation $\rho$ entre les arbres est donc le levier clé, et c'est précisément ce que visent les forêts aléatoires. | |
| - | ### 9.2.3 Forêts aléatoires |
| + | ### 10.2.3 Forêts aléatoires |
| Une forêt aléatoire est du bagging avec sous-échantillonnage des variables : à chaque coupure, seul un sous-ensemble aléatoire de $m_{\text{try}}$ variables est considéré comme candidat. Les choix usuels sont | |
| @@ 122,13 122,13 @@ | |
| T3 --> AGG | |
| ``` | |
| - |  |
| + |  |
| *(a) Un arbre profond seul surajuste avec une frontière en escalier. (b) Une forêt aléatoire moyenne de nombreux arbres pour une frontière plus lisse.* | |
| - | ## 9.3 Boosting |
| + | ## 10.3 Boosting |
| - | ### 9.3.1 Modèle additif |
| + | ### 10.3.1 Modèle additif |
| Le boosting construit un prédicteur comme une somme pondérée de $T$ apprenants faibles $h_t$ (typiquement des arbres peu profonds), ajustés un à un. Le modèle additif est défini par | |
| @@ 136,7 136,7 @@ | |
| Chaque étape corrige les erreurs de la somme courante, donc l'ensemble est construit de façon séquentielle et réduit le biais plutôt que la variance. | |
| - | ### 9.3.2 AdaBoost |
| + | ### 10.3.2 AdaBoost |
| Avec des étiquettes $y\in\{-1,+1\}$, AdaBoost conserve des poids d'exemples $w^{(i)}$ qui se concentrent sur les points actuellement mal classés. Au tour $t$, l'apprenant faible a une erreur pondérée $\varepsilon_t$, et son coefficient est défini par | |
| @@ 148,7 148,7 @@ | |
| puis renormalisés. Les exemples mal classés ($y^{(i)}h_t(x^{(i)})<0$) gagnent du poids, donc l'apprenant suivant se concentre sur eux. | |
| - | ### 9.3.3 Gradient boosting |
| + | ### 10.3.3 Gradient boosting |
| Le gradient boosting généralise l'idée à toute perte différentiable $L$. À l'étape $t$, il ajuste l'apprenant suivant sur l'opposé du gradient de la perte évalué au modèle courant, le pseudo-résidu défini par | |
| fr/Machine Learning/09 Decision trees and ensemble methods/forest-vs-tree.png .. fr/Machine Learning/10 Decision trees and ensemble methods/forest-vs-tree.png | |
| fr/Machine Learning/09 Decision trees and ensemble methods/tree-boundary.png .. fr/Machine Learning/10 Decision trees and ensemble methods/tree-boundary.png | |
