Gini Index Calculator
Calculate the Gini impurity of a node's class distribution for decision tree splitting.
Inputs
Number of samples belonging to each class in the node, e.g. "40, 10, 5".
Gini Index
0.429752
Maximum Possible Gini (Uniform)
0.666667
Dominant Class Share
72.73%
Step by step
Class proportions: count_i / total
[40, 10, 5] ÷ 55
= 0.7273, 0.1818, 0.0909
Sum of squared proportions: Σ p_i²
Σ [0.5289, 0.0331, 0.0083]
= 0.570248
Gini index: 1 − Σ p_i²
1 − 0.570248
= 0.429752
How it works
The Gini index measures node impurity by estimating the probability that two randomly drawn samples from the node belong to different classes: Gini = 1 − Σ p_i², where p_i is the proportion of class i in the node. A Gini of 0 means the node is perfectly pure (all samples belong to one class), while higher values indicate a more evenly mixed distribution — the maximum, 1 − 1/n for n classes, occurs at a perfectly uniform split. CART (Classification and Regression Trees), used by scikit-learn's default DecisionTreeClassifier, uses Gini index rather than entropy as its default splitting criterion because it's slightly cheaper to compute (no logarithms).
Formula
Gini = 1 - sum(p_i ^ 2)
- p_i
- Proportion of class i in the node (count_i / total)
Frequently Asked Questions
How is Gini index different from entropy?
Both measure node impurity and tend to select similar splits in practice, but Gini uses squared proportions (1 − Σp²) while entropy uses logarithms (−Σp·log2(p)); Gini is computationally cheaper since it avoids logarithm calculations, which is why CART/scikit-learn use it as the default criterion.
What is the maximum possible Gini index?
For n classes with a perfectly uniform distribution (each class equally represented), the maximum Gini is 1 − 1/n — for 2 classes that's 0.5, and it approaches 1 as the number of classes grows large.
Why does scikit-learn default to Gini instead of entropy?
Gini index avoids computing logarithms, making it marginally faster to evaluate across many candidate splits during tree construction, and in practice it tends to produce trees very similar in quality to those built with entropy-based information gain.