# Gini Impurity Calculator

> Calculate the Gini impurity of a node from its class counts, with the maximum possible impurity, a normalised score and the entropy for comparison.

Category: Statistics & probability · Applies to: Worldwide · Last updated: 2026-10-29
Interactive calculator: https://calculators.geekmidst.com/calculators/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).

## Inputs
- Items in each class (default 9, 5)

## Results
- Gini impurity
- Maximum for this many classes
- Normalised (0–1)
- Entropy (bits), for comparison
- Total items

## Formula

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

Where:
- 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.

**Result:** 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.

## Related calculators
- [Information Gain Calculator](https://calculators.geekmidst.com/calculators/information-gain-calculator)
- [Shannon Entropy Calculator](https://calculators.geekmidst.com/calculators/entropy-shannon-calculator)
- [Class Imbalance Ratio Calculator](https://calculators.geekmidst.com/calculators/class-imbalance-ratio-calculator)

Source: GM¹X CalcVerse — https://calculators.geekmidst.com/calculators/gini-impurity-calculator
