Random Forest
Random Forest
aléatoires
Les forêts aléatoires sont un algorithme d'apprentissage
automatique puissant et flexible qui peut être utilisé pour une
variété de tâches de prédiction, y compris la classification et la
régression. Elles sont relativement faciles à mettre en œuvre
et sont souvent très précises. Dans cette présentation, nous
allons explorer ce qu'est une forêt aléatoire, quels sont ses
principaux avantages et comment elle fonctionne.
Plan de la Présentation:
1 Introduction
(…)
Majority voting
Result
Qu'est-ce qu'une forêt aléatoire ?
Une forêt aléatoire, en apprentissage automatique, L'idée est de créer une collection d'arbres de
est un algorithme d'ensemble qui combine plusieurs décision diversifiés, qui ne sont pas corrélés les uns
arbres de décision, chacun étant formé sur un sous- aux autres, et qui peuvent donc compenser les
ensemble aléatoire des données d'apprentissage. faiblesses de chaque arbre individuel. Cette
Chaque arbre de décision vote pour une prédiction, approche permet de réduire le risque de sur-
et la prédiction de la forêt est basée sur la majorité apprentissage et d'obtenir des prédictions plus
des votes. robustes.
Avantages des forêts aléatoires
Subset 2
: ID y
6 13 0 0 2 6 49 53 61 4,2 1 9 2
2 14 1 9 0 9 94 57 49 5,7 3,5 5,3 0
4 11 1 7 4 5 56 47 82 8 3,3 2,1 1
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
3 10 1 6 10 5 57 66 95 7 7,4 8 2
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
Bootstrap Sampling :
Subset 3
: ID y
3 10 1 6 10 5 57 66 95 7 7,4 8 2
3 10 1 6 10 5 57 66 95 7 7,4 8 2
3 10 1 6 10 5 57 66 95 7 7,4 8 2
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
6 13 0 0 2 6 49 53 61 4,2 1 9 2
3 10 1 6 10 5 57 66 95 7 7,4 8 2
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
Bootstrap Sampling :
Subset 4
: ID y
4 11 1 7 4 5 56 47 82 8 3,3 2,1 1
6 13 0 0 2 6 49 53 61 4,2 1 9 2
3 10 1 6 10 5 57 66 95 7 7,4 8 2
7 13 1 9 2 10 48 88 45 9,5 1,9 5 0
4 11 1 7 4 5 56 47 82 8 3,3 2,1 1
6 13 0 0 2 6 49 53 61 4,2 1 9 2
3 10 1 6 10 5 57 66 95 7 7,4 8 2
Decision Tree 1
91 𝑥 9 <6 , 5
𝑥 4 <7 ,5
𝑥 3< 7 , 5
𝑥 2< 4 ,5 88
𝑥 2< 4 ,5
𝑥7 < 4 ,5 𝑥7 < 4 ,5
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 Class 1 Class 0 Class 2 Class 2
𝑥 3< 4 ,5 𝑥 3< 4 ,5 𝑥 3< 5 , 5 𝑥 2< 4 ,5
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 Class 1 Class 0 Class 2 Class 2
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥𝑥
012 3
𝑥
4 𝑥
5 𝑥
6 7𝑥 8 𝑥 9𝑥 10
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8
𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8
𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 0 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 0 2 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8
𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 0 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 0 2 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8
𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 0 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 0 2 𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
7.12
[ 11 , 0 , 6 , 10 , 4 , 40 , 68 , 78 , 2.68 , 8.58 , 7.12]
𝑥𝑥𝑥 𝑥
001 𝑥12 𝑥𝑥
2 𝑥
3
3 4
𝑥
4 𝑥
5
5 𝑥 𝑥
6𝑥
6 7
7
𝑥 8
8 𝑥 9 𝑥10
9𝑥 10
𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3 𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 0 𝑐 𝑙𝑎𝑠𝑠 2𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 3𝑐 𝑙𝑎𝑠𝑠 1 𝑐 𝑙𝑎𝑠𝑠 0𝑐 𝑙𝑎𝑠𝑠 2 𝑐 𝑙𝑎𝑠𝑠 2
3 1 1 2
3 1 1 2
1
Pseudo-code de
la construction
d'un arbre de
décision
Pseudo-code de la
construction d'un arbre de
décision
CLASSE DecisionTree:
CONSTRUCTEUR(max_depth = null): O(1)
max_depth = profondeur maximale de l'arbre
tree = null // L'arbre sera construit lors de
l'entraînement (fit)
O(d*log(n))
MÉTHODE fit(X, y):
tree = construire_arbre(X, y, profondeur=0)
MÉTHODE predict(X):
O(log(n))
POUR CHAQUE ligne DANS X:
prédiction = prédire_ligne(ligne, tree)
AJOUTER prédiction à la liste des
prédictions
RETOURNER liste des prédictions
Pseudo-code de la
construction d'un arbre de
décision
CLASSE DecisionTree: O(d*log(n))
MÉTHODE construire_arbre(X, y, profondeur):
// Conditions d'arrêt
SI toutes les classes dans y sont identiques OU
profondeur >= max_depth:
RETOURNER classe_majoritaire(y) // Classe la plus fréquente
// Trouver la meilleure séparation (split)
meilleure_feature, meilleur_seuil = trouver_meilleur_split(X, y)
RETOURNER {
"feature": meilleure_feature,
"threshold": meilleur_seuil,
"left": sous_arbre_gauche,
"right": sous_arbre_droit
}
Pseudo-code de la
construction d'un arbre de
décision
CLASSE DecisionTree:
MÉTHODE trouver_meilleur_split(X, y): O(d*)
meilleur_gain = -1
meilleure_feature = null
meilleur_seuil = null
POUR CHAQUE feature DANS X.colonnes:
POUR CHAQUE valeur_unique DANS X[feature]:
gain = calculer_gain_information(X, y,
feature, valeur_unique)
SI gain > meilleur_gain:
meilleur_gain = gain
meilleure_feature = feature
meilleur_seuil = valeur_unique
RETOURNER meilleure_feature, meilleur_seuil
Pseudo-code de la
construction d'un arbre de
décision
CLASSE DecisionTree:
MÉTHODE calculer_gain_information(X, y, feature, seuil):
y_gauche = y[X[feature] <= seuil]
y_droite = y[X[feature] > seuil] O(n)
SI y_gauche.vide OU y_droite.vide:
RETOURNER 0
entropie_totale = calculer_entropie(y)
entropie_gauche = calculer_entropie(y_gauche)
entropie_droite = calculer_entropie(y_droite)
poids_gauche = len(y_gauche) / len(y)
poids_droit = len(y_droite) / len(y)
RETOURNER entropie_totale –
(poids_gauche * entropie_gauche +
poids_droit * entropie_droite)
Rappel :
MÉTHODE vote_majoritaire(predictions_arbres):
// Effectuer un vote majoritaire sur les prédictions
pour chaque index de ligne dans predictions_arbres:
RETOURNER classe la plus fréquente
parmi les prédictions
Rappel :
Où :
• T est le nombre d'arbres.
• 1 est une fonction indicatrice qui vaut 1 si l'arbre i prédit
la classe c, et 0 sinon.
Implémentation
dans les trois
langages
Comparaison des
Performances
des Langages
Python, R et Julia
from scratch
Comparaison des Langages pour un Random Forest From Scratch
Critère R Python Julia