Gini Impurity Calculator

Gini impurity is the chance that two items drawn at random (with replacement) from a node belong to different classes. A pure node scores 0.

Also called: Gini index calculator (decision trees)

  • Last updated
  • Formula tested against reference values

Your numbers

Counts or proportions for each class in the node.

Result

Gini impurity
—

Calculating…

Maximum for this many classes
—
Normalised (0–1)
—
Entropy (bits), for comparison
—
Total items
—

How to use this calculator

  1. Enter or choose items in each class.
  2. The gini impurity updates as you type. Use Copy result or Share to keep it.

Method

G = 1 − Σ p_i²; G_max = 1 − 1 ÷ k

p_i
share of items in class i
k
number of classes

Worked example

  1. Shares: 9 ÷ 14 and 5 ÷ 14.
  2. G = 1 − (81 + 25) ÷ 196 = 90 ÷ 196 = 0.459184.

A node with 9 and 5 items has Gini impurity 0.459, close to the two-class maximum of 0.5.

What the result means

Decision trees (CART) choose the split that most reduces weighted Gini impurity. It is not the Gini coefficient of inequality used in economics.

Assumptions and limits

  • Class shares are estimated from the counts in the node.
  • To score a whole split, use the information gain calculator with the Gini criterion.

Questions

Gini or entropy?

They rank splits almost identically in practice. Gini is slightly cheaper to compute; entropy penalises very impure nodes a little more.

Is this the same as the Gini coefficient?

No. The Gini coefficient measures inequality of a distribution, such as income; Gini impurity measures class mixing in a node.