Blame

d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
1
# 5. Arbres de décision et méthodes d'ensemble
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 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.
4
5
**Objectifs**
6
- Exprimer un arbre comme une fonction constante par morceaux et choisir les coupures avec un critère d'impureté.
7
- Contrôler le surapprentissage par l'élagage à complexité coûteuse.
8
- Réduire la variance par le bagging et décorréler les arbres via le sous-échantillonnage des variables.
9
- Estimer gratuitement l'erreur de généralisation avec les échantillons hors-sac.
10
- Construire un prédicteur fort comme somme additive d'apprenants faibles (AdaBoost, gradient boosting).
11
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
12
## 5.1 Arbres de décision CART
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>
13
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
14
### 5.1.1 L'arbre comme partition
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>
15
16
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
17
18
$$\boxed{ h(x)=\sum_{m=1}^{M} c_m\,\mathbf{1}\{x\in R_m\} }$$
19
20
Chaque nœud interne teste une variable contre un seuil, $x_j\le s$, envoyant un exemple à gauche ou à droite. Un chemin de la racine à une feuille est une conjonction de tels tests.
21
22
*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.
23
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
24
### 5.1.2 Impureté et choix de la coupure
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>
25
26
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
27
28
$$\boxed{ G = 1-\sum_{k}\hat p_k^{\,2} }$$
29
30
et l'entropie par
31
32
$$\boxed{ H = -\sum_{k}\hat p_k\log_2\hat p_k }$$
33
34
Une coupure candidate envoie $N_-$ exemples vers l'enfant $R_-$ et $N_+$ vers $R_+$ sur $N$ au total. Son gain d'information est défini par
35
36
$$\boxed{ IG = I(\text{parent})-\frac{N_-}{N}\,I(R_-)-\frac{N_+}{N}\,I(R_+) }$$
37
38
où $I$ est l'impureté choisie. CART retient gloutonnement la variable et le seuil qui maximisent $IG$ à chaque nœud.
39
40
| critère | formule | plage (binaire) | note |
41
| --- | --- | --- | --- |
42
| Gini | $1-\sum_k\hat p_k^{2}$ | $[0,0.5]$ | moins coûteux, sans logarithme |
43
| entropie | $-\sum_k\hat p_k\log_2\hat p_k$ | $[0,1]$ | théorie de l'information |
44
45
*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.
46
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
47
### 5.1.3 Arbres de régression
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
48
49
En régression, la valeur de la feuille est la moyenne des cibles dans la région, définie par
50
51
$$\boxed{ c_m=\frac{1}{N_m}\sum_{x^{(i)}\in R_m} y^{(i)} }$$
52
53
et les coupures minimisent l'erreur quadratique intra-région plutôt qu'une impureté de classification.
54
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
55
### 5.1.4 Élagage
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56
57
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$ :
58
59
$$\boxed{ C_\alpha(T)=\sum_{m} N_m\,I(R_m)+\alpha\,|T| }$$
60
61
Augmenter $\alpha$ effondre les coupures les plus faibles, produisant une suite emboîtée de sous-arbres. Le meilleur $\alpha$ est choisi par validation croisée.
62
63
```mermaid
64
graph TD
65
A["x_j <= s ?"] -->|"oui"| B["x_k <= t ?"]
66
A -->|"non"| C["feuille R3"]
67
B -->|"oui"| D["feuille R1"]
68
B -->|"non"| E["feuille R2"]
69
```
70
71
![Régions d'un arbre de décision](/fr/Machine%20Learning/05%20Decision%20trees%20and%20ensemble%20methods/a/tree-boundary.png)
72
73
*Un arbre découpe l'espace en régions alignées sur les axes, chacune à prédiction constante.*
74
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
75
## 5.2 Forêts aléatoires
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
77
### 5.2.1 Bagging
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
78
79
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
80
81
$$\boxed{ h_{\text{bag}}(x)=\frac{1}{B}\sum_{b=1}^{B} h_b(x) }$$
82
83
En classification, la moyenne est remplacée par un vote majoritaire. Moyenner laisse le biais inchangé tout en réduisant la variance.
84
85
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).
86
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
87
### 5.2.2 Variance d'une moyenne
1c3139 Lucas Gonthier 2026-06-30 12:04:21
Initial commit: course content (Machine Learning, MLOps) in EN and FR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
88
89
Si les $B$ arbres ont chacun une variance $\sigma^2$ et une corrélation deux à deux $\rho$, la variance de leur moyenne vaut
90
91
$$\boxed{ \rho\sigma^2+\frac{1-\rho}{B}\,\sigma^2 }$$
92
93
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.
94
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
95
### 5.2.3 Forêts aléatoires
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
97
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
98
99
$$\boxed{ m_{\text{try}}=\lfloor\sqrt{n}\,\rfloor\ \text{(classification)},\qquad m_{\text{try}}=\lfloor n/3\rfloor\ \text{(régression)} }$$
100
101
Restreindre les variables candidates empêche tous les arbres de couper sur la même variable dominante, ce qui décorrèle les arbres et abaisse $\rho$.
102
103
*Remarque :* l'erreur OOB moyenne l'erreur de chaque arbre uniquement sur les exemples qu'il n'a jamais vus, donnant une estimation proche d'une validation croisée sans coût supplémentaire.
104
105
| propriété | bagging | forêt aléatoire |
106
| --- | --- | --- |
107
| rééchantillonnage | bootstrap | bootstrap |
108
| variables candidates | les $n$ variables | $m_{\text{try}}$ variables aléatoires |
109
| corrélation des arbres $\rho$ | plus élevée | plus faible |
110
| réduction de variance | modérée | plus forte |
111
112
```mermaid
113
graph TD
114
A["jeu d'entrainement"] --> B1["echantillon bootstrap 1"]
115
A --> B2["echantillon bootstrap 2"]
116
A --> B3["echantillon bootstrap B"]
117
B1 --> T1["arbre 1"]
118
B2 --> T2["arbre 2"]
119
B3 --> T3["arbre B"]
120
T1 --> AGG["agregation : moyenne ou vote"]
121
T2 --> AGG
122
T3 --> AGG
123
```
124
125
![Arbre seul et forêt aléatoire](/fr/Machine%20Learning/05%20Decision%20trees%20and%20ensemble%20methods/a/forest-vs-tree.png)
126
127
*(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.*
128
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
129
## 5.3 Boosting
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>
130
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
131
### 5.3.1 Modèle additif
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
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
134
135
$$\boxed{ H_T(x)=\sum_{t=1}^{T}\alpha_t\,h_t(x) }$$
136
137
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.
138
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
139
### 5.3.2 AdaBoost
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>
140
141
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
142
143
$$\boxed{ \alpha_t=\tfrac12\log\frac{1-\varepsilon_t}{\varepsilon_t} }$$
144
145
ainsi un apprenant plus précis ($\varepsilon_t$ petit) obtient un vote plus grand. Les poids sont ensuite mis à jour par
146
147
$$\boxed{ w^{(i)}\leftarrow w^{(i)}\exp\!\big(-\alpha_t\,y^{(i)}h_t(x^{(i)})\big) }$$
148
149
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.
150
d5b8b5 lugonthier 2026-07-01 14:24:01
Refactor section headings for consistency and clarity across multiple documents in the Machine Learning module. Updated headings to include numerical prefixes for better organization and navigation. Adjusted content formatting and improved terminology in French translations for decision trees, ensemble methods, and other foundational concepts.
151
### 5.3.3 Gradient boosting
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>
152
153
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
154
155
$$\boxed{ r^{(i)}_t=-\left[\frac{\partial L\big(y^{(i)},f(x^{(i)})\big)}{\partial f}\right]_{f=H_{t-1}} }$$
156
157
Le modèle est ensuite mis à jour avec un taux d'apprentissage (rétrécissement) $\nu\in(0,1]$ :
158
159
$$\boxed{ H_t=H_{t-1}+\nu\,\alpha_t\,h_t }$$
160
161
*Remarque :* avec une perte quadratique, le pseudo-résidu est simplement le résidu ordinaire $y^{(i)}-H_{t-1}(x^{(i)})$, donc chaque arbre ajuste ce que le modèle courant se trompe encore.
162
163
| propriété | bagging | boosting |
164
| --- | --- | --- |
165
| entraînement | parallèle, indépendant | séquentiel, chacun sur les erreurs précédentes |
166
| apprenants de base | profonds, faible biais | peu profonds, fort biais |
167
| réduit surtout | la variance | le biais |
168
| repondération | aucune (bootstrap) | poids ou pseudo-résidus |
169
170
```mermaid
171
graph LR
172
A["apprenant faible 1"] --> B["apprenant faible 2"]
173
B --> C["apprenant faible 3"]
174
C --> D["apprenant faible T"]
175
D --> E["somme ponderee H_T"]
176
```
177
178
*Ceci complète le cœur du cours sur l'apprentissage supervisé. Pour faire passer ces modèles d'un notebook à un service en production, poursuivez avec le cours [MLOps](/fr/MLOps).*
179
180
---
181
Suivant : [Vue d'ensemble du cours](/fr/Machine%20Learning)