• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Entropy-based Information Gain requires logarithmic computations, which are relatively expensive. Decision tree algorithms need a faster impurity measure that produces similar quality splits without the computational overhead.

Core Idea

The Gini Index measures the probability that a randomly chosen element from a dataset would be incorrectly classified if it were labeled according to the class distribution in that dataset. Lower Gini Index means purer subsets; a Gini of 0 indicates perfect purity.

How It Works

The Gini Index formula:

Gini=1i=1npi2Gini = 1 - \sum_{i=1}^{n} p_i^2

Where pip_i is the probability of class ii in the dataset.

Key behaviors:

  • Perfect purity (Gini = 0): All instances belong to one class → pi2=1\sum p_i^2 = 1Gini=0Gini = 0
    • Example: 100% “Yes” → 112=01 - 1^2 = 0
  • Maximum impurity (binary, Gini = 0.5): Equal class distribution → pi2=0.5\sum p_i^2 = 0.5Gini=0.5Gini = 0.5
    • Example: 50% “Yes”, 50% “No” → 1(0.25+0.25)=0.51 - (0.25 + 0.25) = 0.5

How it’s used in splitting:

  1. Calculate the Gini Index for each potential split
  2. Compute the weighted Gini of the child nodes
  3. Choose the split with the lowest weighted Gini Index

The Gini Index is the default criterion in scikit-learn’s DecisionTreeClassifier. It is faster to compute than entropy (no logarithms needed — just squaring and summing probabilities) and is more sensitive to changes in class probabilities near the extremes.

Visual Explanation

gini_index dataset Dataset Class Distribution probs Calculate pᵢ for each class dataset->probs square Square each pᵢ Sum them up probs->square formula Gini = 1 - Σ(pᵢ²) square->formula result Gini Value 0 = pure 0.5 = max (binary) formula->result

Key Properties

  • Range [0, 0.5]: For binary classification, Gini ranges from 0 (pure) to 0.5 (max impurity)
  • Faster than entropy: No logarithm computation — only multiplication and addition
  • Sensitive to changes: More responsive to shifts in class probabilities near the extremes
  • Default in sklearn: The most commonly used impurity measure in practice

Connections

Edge Cases & Gotchas

  • Favors equal-sized splits: Tends to prefer splits that create balanced child nodes, even if not optimal for accuracy
  • Multi-class scaling: Maximum Gini increases with more classes: 11/c1 - 1/c for cc classes
  • Near-pure insensitivity: When nodes are nearly pure, Gini changes are very small, which can cause premature stopping
  • Not information-theoretic: Unlike entropy, Gini has no connection to information theory or bits