Blame

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.
1
# 7. Machines à vecteurs de support
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
3
Les machines à vecteurs de support sont des classifieurs linéaires à grande marge. Elles
4
choisissent la frontière qui maximise la distance aux points les plus proches, contrôlent le
5
surapprentissage avec la perte charnière et une pénalité $C$, et utilisent des noyaux pour
6
ajuster des frontières non linéaires sans jamais former l'application de caractéristiques. Partout,
7
les étiquettes valent $y \in \{-1,+1\}$ et la décision utilise un score brut $z = w^T x - b$.
8
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.
9
## 7.1 Classifieur à marge optimale
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>
10
11
Les étiquettes valent $y \in \{-1,+1\}$, avec un vecteur de poids $w \in \mathbb{R}^{n}$ et un biais $b$.
12
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.
13
### 7.1.1 Hypothèse et frontière
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
15
L'hypothèse est définie comme le signe du score brut $z = w^T x - b$ :
16
17
$$\boxed{ h(x) = \operatorname{sign}(w^T x - b) }$$
18
19
La frontière de décision est l'ensemble des points de score nul :
20
21
$$\boxed{ w^T x - b = 0 }$$
22
23
*Remarque :* $w$ est orthogonal à la frontière, il en fixe donc l'orientation, et $b$ fixe le décalage.
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
### 7.1.2 Marge géométrique
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>
26
27
La marge géométrique de l'exemple $i$ est définie comme sa distance signée à la frontière, rendue
28
positive par l'étiquette :
29
30
$$\boxed{ \gamma^{(i)} = y^{(i)} \, \frac{w^T x^{(i)} - b}{\lVert w \rVert} }$$
31
32
Un point correctement classé vérifie $\gamma^{(i)} > 0$. La marge du jeu de données est la plus
33
petite $\gamma^{(i)}$ sur tous les exemples.
34
35
*Remarque :* diviser par $\lVert w \rVert$ rend la marge invariante au rééchelonnement de $(w,b)$,
36
contrairement au score brut $z$.
37
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.
38
### 7.1.3 Primal à marge dure
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>
39
40
En fixant l'échelle pour que les points les plus proches vérifient $y^{(i)}(w^T x^{(i)} - b) = 1$,
41
maximiser la marge équivaut à minimiser $\lVert w \rVert^2$ sous une marge fonctionnelle unitaire :
42
43
$$\boxed{ \min_{w,b} \tfrac{1}{2}\lVert w \rVert^2 \quad \text{s.c.} \quad y^{(i)}(w^T x^{(i)} - b) \ge 1 \ \ \forall i }$$
44
45
C'est un programme quadratique convexe à contraintes linéaires, il admet donc un optimum unique.
46
47
*Remarque :* il exige des données linéairement séparables. La leçon suivante assouplit cela avec
48
des variables d'écart.
49
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.
50
![Marge SVM et vecteurs de support](/fr/Machine%20Learning/07%20Support%20Vector%20Machines/a/svm-margin.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>
51
52
*L'hyperplan optimal (trait plein) maximise la marge (pointillés). Les points entourés sont les vecteurs de support.*
53
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.
54
## 7.2 Perte charnière
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>
55
56
Le score brut est $z = w^T x - b$ et les étiquettes valent $y \in \{-1,+1\}$.
57
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.
58
### 7.2.1 Perte charnière
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>
59
60
La perte charnière est définie comme l'écart par lequel la marge $yz$ tombe sous $1$, tronqué à zéro :
61
62
$$\boxed{ L(z,y) = \max(0,\, 1 - yz), \quad z = w^T x - b }$$
63
64
Elle est nulle dès que $yz \ge 1$ (le point est correct et au-delà de la marge) et croît
65
linéairement à l'intérieur ou au-delà de la marge.
66
67
*Remarque :* la perte charnière est convexe mais non dérivable en $yz = 1$, on l'optimise donc
68
avec des sous-gradients.
69
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.
70
### 7.2.2 Primal à marge souple
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>
71
72
On introduit un écart $\xi_i \ge 0$ par exemple pour autoriser les violations de marge, pénalisé
73
par $C > 0$ :
74
75
$$\boxed{ \min_{w,b,\xi} \tfrac{1}{2}\lVert w \rVert^2 + C\sum_{i=1}^{m}\xi_i \quad \text{s.c.} \quad y^{(i)}(w^T x^{(i)} - b) \ge 1 - \xi_i, \ \ \xi_i \ge 0 }$$
76
77
À l'optimum $\xi_i = \max(0,\, 1 - y^{(i)}(w^T x^{(i)} - b))$, donc éliminer les écarts donne la
78
forme régularisée sans contrainte :
79
80
$$\boxed{ \min_{w,b} \tfrac{1}{2}\lVert w \rVert^2 + C\sum_{i=1}^{m}\max\!\big(0,\, 1 - y^{(i)}(w^T x^{(i)} - b)\big) }$$
81
82
C'est de la régularisation plus une perte charnière : le terme $\tfrac{1}{2}\lVert w \rVert^2$
83
élargit la marge et la somme pénalise les violations.
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
### 7.2.3 Rôle de $C$
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
87
| $C$ | Pénalité des violations | Marge | Comportement |
88
| --- | --- | --- | --- |
89
| petit | faible | large | plus de violations tolérées, variance plus faible |
90
| grand | forte | étroite | moins de violations, ajuste davantage les données |
91
92
*Remarque :* quand $C \to \infty$ aucune violation n'est tolérée, ce qui redonne le classifieur à
93
marge dure.
94
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.
95
## 7.3 Noyaux
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
### 7.3.1 Définition d'un noyau
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
99
Un noyau est défini comme le produit scalaire d'une application de caractéristiques $\phi$
100
appliquée à deux entrées :
101
102
$$\boxed{ K(x,z) = \phi(x)^T \phi(z) }$$
103
104
Un noyau valide calcule ce produit scalaire directement, donc $\phi$ n'a jamais à être formée
105
(elle peut même être de dimension infinie).
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
### 7.3.2 Astuce du noyau
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
109
Le dual du SVM ne dépend des données qu'à travers des produits scalaires
110
$\langle x^{(i)}, x^{(j)} \rangle$. L'astuce du noyau remplace chaque produit scalaire par un noyau :
111
112
$$\boxed{ \langle x^{(i)}, x^{(j)} \rangle \ \longrightarrow \ K(x^{(i)}, x^{(j)}) }$$
113
114
Cela ajuste une frontière linéaire dans l'espace de caractéristiques, donc non linéaire dans
115
l'espace d'origine, au prix d'évaluer $K$ au lieu de $\phi$.
116
117
Un choix très répandu est le noyau gaussien (RBF) :
118
119
$$\boxed{ K(x,z) = \exp\!\left( -\frac{\lVert x - z \rVert^2}{2\sigma^2} \right) }$$
120
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.
121
### 7.3.3 Condition de Mercer
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>
122
123
Une fonction $K$ est un noyau valide si et seulement si, pour tout échantillon fini, sa matrice de
124
Gram est symétrique semi-définie positive :
125
126
$$\boxed{ K = K^T, \qquad K \succeq 0 }$$
127
128
*Remarque :* c'est la condition de Mercer. Elle garantit l'existence d'une application $\phi$, donc
129
le dual reste convexe.
130
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.
131
### 7.3.4 Noyaux usuels
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>
132
133
| Noyau | $K(x,z)$ | Note |
134
| --- | --- | --- |
135
| Linéaire | $x^T z$ | pas d'application, redonne le SVM linéaire |
136
| Polynomial | $(x^T z + c)^d$ | degré $d$, décalage $c$ |
137
| Gaussien (RBF) | $\exp\!\big(-\tfrac{\lVert x - z \rVert^2}{2\sigma^2}\big)$ | dimension infinie, local |
138
139
*Remarque :* un petit $\sigma$ rend le noyau RBF très local, ce qui peut surapprendre. Il se règle
140
en compromis avec $C$.
141
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.
142
![Frontière de décision avec noyau RBF](/fr/Machine%20Learning/07%20Support%20Vector%20Machines/a/svm-kernel.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>
143
144
*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.*
145
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.
146
## 7.4 Lagrangien et dualité
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>
147
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.
148
### 7.4.1 Lagrangien
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>
149
150
Pour un objectif primal $f(w)$ avec contraintes d'inégalité $g_i(w) \le 0$ et multiplicateurs
151
$\beta_i \ge 0$, le lagrangien est défini comme :
152
153
$$\boxed{ \mathcal{L}(w,\beta) = f(w) + \sum_{i=1}^{m} \beta_i \, g_i(w) }$$
154
155
Appliqué au primal SVM $\tfrac{1}{2}\lVert w \rVert^2$ avec contraintes
156
$1 - y^{(i)}(w^T x^{(i)} - b) \le 0$, les conditions de stationnarité $\nabla_w \mathcal{L} = 0$ et
157
$\partial_b \mathcal{L} = 0$ donnent :
158
159
$$\boxed{ w = \sum_{i=1}^{m} \beta_i\, y^{(i)} x^{(i)}, \qquad \sum_{i=1}^{m} \beta_i\, y^{(i)} = 0 }$$
160
161
Le $w$ optimal est donc une combinaison linéaire des entrées d'apprentissage pondérées par
162
$\beta_i y^{(i)}$.
163
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.
164
### 7.4.2 Problème dual
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>
165
166
En réinjectant ces relations, on élimine $w$ et $b$, ce qui laisse un problème en $\beta$ ne
167
dépendant des données qu'à travers des produits scalaires :
168
169
$$\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 }$$
170
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.
171
Les produits scalaires sont exactement l'endroit où l'on substitue un noyau $K$ (voir [Noyaux](/fr/Machine%20Learning/07%20Support%20Vector%20Machines#73-noyaux)).
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>
172
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.
173
### 7.4.3 KKT et vecteurs de support
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>
174
175
À l'optimum, l'écart complémentaire lie chaque multiplicateur à sa contrainte :
176
177
$$\boxed{ \beta_i \big[\, y^{(i)}(w^T x^{(i)} - b) - 1 \,\big] = 0 }$$
178
179
Les vecteurs de support sont définis comme les exemples à multiplicateur non nul :
180
181
$$\boxed{ \text{vecteurs de support} = \{\, i : \beta_i > 0 \,\} }$$
182
183
Ce sont les points exactement sur la marge. Tous les autres ont $\beta_i = 0$ et n'influencent pas
184
$w$.
185
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.
186
### 7.4.4 Décision à noyau
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
188
Remplacer le produit scalaire par un noyau donne une règle de décision exprimée uniquement à
189
travers les vecteurs de support :
190
191
$$\boxed{ h(x) = \operatorname{sign}\!\left( \sum_{i=1}^{m} \beta_i\, y^{(i)}\, K(x^{(i)}, x) - b \right) }$$
192
193
*Remarque :* seuls les vecteurs de support ($\beta_i > 0$) contribuent, donc le coût de prédiction
194
croît avec leur nombre, pas avec $m$.
195
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.
196
### 7.4.5 Du primal à la décision
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>
197
198
```mermaid
199
flowchart TD
200
A["QP primal : minimiser demi norme au carre"]
201
B["lagrangien avec multiplicateurs"]
202
C["probleme dual en beta"]
203
D["conditions KKT"]
204
E["vecteurs de support : beta superieur a zero"]
205
F["regle de decision a noyau"]
206
A --> B
207
B --> C
208
C --> D
209
D --> E
210
E --> F
211
```
212
213
*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.*
214
215
---
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.
216
Suivant : [Arbres de décision et méthodes d'ensemble](/fr/Machine%20Learning/08%20Decision%20trees%20and%20ensemble%20methods) · [Vue d'ensemble du cours](/fr/Machine%20Learning)