Skip to content
ENExplore Calculators

Gini Index Calculator

Calculate the Gini impurity index used for evaluating decision tree splits.

About Gini Index Calculator

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)

Worked example

With the default values below, Gini Index Calculator returns Gini Index of 0.429752. Change any input above and every figure here is recalculated in your browser.

Inputs used

Class Counts (comma-separated)
40, 10, 5

Results

Gini Index
0.429752
Maximum Possible Gini (Uniform)
0.666667
Dominant Class Share
72.73%

Step by step

  1. 1Class proportions: count_i / total= 0.7273, 0.1818, 0.0909
  2. 2Sum of squared proportions: Σ p_i²= 0.570248
  3. 3Gini index: 1 − Σ p_i²= 0.429752

Assumptions and limits

  • The result is derived only from the single input listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

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.

Gini Index Calculator – Calculate Gini Index | Calcrivo