SOLUTION DETAILLEE
Prenez le temps de comparer avec vos reponses. Verifiez chaque etape !
RAPPEL : Formule de Gini
$$Gini = 1 - \sum_{i} p_i^2 = 1 - p_{SPAM}^2 - p_{HAM}^2$$
PARTIE 1 : Gini du noeud racine
- Total : 10 emails
- SPAM : 5 β $p_{SPAM} = \frac{5}{10} = \textcolor{#e74c3c}{0.5}$
- HAM : 5 β $p_{HAM} = \frac{5}{10} = \textcolor{#27ae60}{0.5}$
$$Gini_{racine} = 1 - \textcolor{#e74c3c}{0.5}^2 - \textcolor{#27ae60}{0.5}^2 = 1 - 0.25 - 0.25$$
$\boxed{Gini_{racine} = \textcolor{#9B7AC4}{0.5}}$
$Gini = 0.5$ est le maximum d'impurete possible pour 2 classes. Le noeud est parfaitement mixte (50/50).
PARTIE 2 : Split sur "Mots majuscules"
- Branche "Beaucoup" (4 emails) : emails 1, 2, 3, 9 β $\textcolor{#e74c3c}{4\ SPAM}$, $\textcolor{#27ae60}{0\ HAM}$
- Branche "Peu" (6 emails) : emails 4, 5, 6, 7, 8, 10 β $\textcolor{#e74c3c}{1\ SPAM}$, $\textcolor{#27ae60}{5\ HAM}$
$$Gini_{Beaucoup} = 1 - \left(\frac{4}{4}\right)^2 - \left(\frac{0}{4}\right)^2 = 1 - 1 - 0$$
$\boxed{Gini_{Beaucoup} = \textcolor{#27ae60}{0} \text{ (pur !)}}$
$$Gini_{Peu} = 1 - \left(\frac{1}{6}\right)^2 - \left(\frac{5}{6}\right)^2 = 1 - 0.028 - 0.694$$
$\boxed{Gini_{Peu} = \textcolor{#e67e22}{0.278}}$
$$Gini_{split} = \frac{4}{10} \times \textcolor{#27ae60}{0} + \frac{6}{10} \times \textcolor{#e67e22}{0.278}$$
$$Gini_{split} = 0 + 0.167$$
$\boxed{Gini_{majuscules} = \textcolor{#3498db}{0.167}}$
PARTIE 3 : Split sur "Contient gratuit"
- Branche "Oui" (4 emails) : emails 1, 2, 4, 10 β $\textcolor{#e74c3c}{3\ SPAM}$, $\textcolor{#27ae60}{1\ HAM}$
- Branche "Non" (6 emails) : emails 3, 5, 6, 7, 8, 9 β $\textcolor{#e74c3c}{2\ SPAM}$, $\textcolor{#27ae60}{4\ HAM}$
$$Gini_{Oui} = 1 - \left(\frac{3}{4}\right)^2 - \left(\frac{1}{4}\right)^2 = 1 - 0.5625 - 0.0625$$
$\boxed{Gini_{Oui} = \textcolor{#e67e22}{0.375}}$
$$Gini_{Non} = 1 - \left(\frac{2}{6}\right)^2 - \left(\frac{4}{6}\right)^2 = 1 - 0.111 - 0.444$$
$\boxed{Gini_{Non} = \textcolor{#e67e22}{0.444}}$
$$Gini_{split} = \frac{4}{10} \times \textcolor{#e67e22}{0.375} + \frac{6}{10} \times \textcolor{#e67e22}{0.444}$$
$$Gini_{split} = 0.15 + 0.267$$
$\boxed{Gini_{gratuit} = \textcolor{#F7E64D}{0.417}}$
PARTIE 4 : Choix du meilleur split
| Split | Gini apres split | Reduction |
|---|
| Mots majuscules | 0.167 | Meilleur |
| Contient gratuit | 0.417 | Moins bon |
$$Gain = Gini_{avant} - Gini_{apres}$$
- Gain (majuscules) = $0.5 - 0.167 = \textcolor{#27ae60}{\mathbf{0.333}}$
- Gain (gratuit) = $0.5 - 0.417 = \textcolor{#e67e22}{0.083}$
$\boxed{\text{L'algorithme choisira "Mots majuscules" (gain = 0.333)}}$
Car ce split reduit le plus l'impurete.
PARTIE 5 : Prediction
Nouvel email : Mots majuscules = "Beaucoup", Contient "gratuit" = "Non"
- On suit le split "Mots majuscules"
- "Beaucoup" β branche gauche
- Cette branche contient 4 SPAM, 0 HAM
- Prediction : $\textcolor{#e74c3c}{\mathbf{SPAM}}$
$$Confiance = \frac{4}{4} = 100\%$$
$\boxed{\text{Prediction : SPAM avec 100\% de confiance}}$
RESUME DES RESULTATS
| Metrique | Mots majuscules | Contient gratuit |
|---|
| Gini branche 1 | 0.000 (pur) | 0.375 |
| Gini branche 2 | 0.278 | 0.444 |
| Gini pondere | 0.167 | 0.417 |
| Gain | 0.333 | 0.083 |
- $\textcolor{#e74c3c}{Rouge}$ : classe SPAM et proportions
- $\textcolor{#27ae60}{Vert}$ : classe HAM, Gini pur (0), meilleur gain
- $\textcolor{#9B7AC4}{Violet}$ : Gini racine (0.5)
- $\textcolor{#e67e22}{Orange}$ : Gini intermediaires
- $\textcolor{#3498db}{Bleu}$ : Gini final du meilleur split
- $\textcolor{#F7E64D}{Jaune}$ : Gini du split moins performant