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.
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.
The Gini Index formula:
Where is the probability of class in the dataset.
Key behaviors:
- Perfect purity (Gini = 0): All instances belong to one class → →
- Example: 100% “Yes” →
- Maximum impurity (binary, Gini = 0.5): Equal class distribution → →
- Example: 50% “Yes”, 50% “No” →
How it’s used in splitting:
- Calculate the Gini Index for each potential split
- Compute the weighted Gini of the child nodes
- 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.
- 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
- Contrasts with: Entropy — Gini uses squared probabilities; entropy uses logarithms
- Builds into: Decision Tree Splitting — Gini determines the best split
- Built from: Node Purity — Gini quantifies the purity concept
- Builds into: Attribute Selection Measures — Gini is a selection criterion
- Related: Information Gain — both serve the same purpose with different formulas
- Builds into: Gini Index Properties — detailed characteristics and trade-offs
- Related: Entropy vs Gini Compared — synthesis comparing both measures
- 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: for 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