Calculate the Gini coefficient (Gini index) from a list of incomes or other values, or Gini impurity from class counts for a decision tree node.
Related Calculators
- Gain Ratio Calculator
- Dominance Index Calculator
- Concordance Index Calculator
- Gamma Index Calculator
- All Statistics Calculators
Gini Index Formula
The following formula is used to calculate the Gini Index (Gini coefficient) from non-negative data sorted in ascending order.
GI = 1 + 1/n – (2 / (n * ฮฃ(i=1)(n) yi)) * ฮฃ(i=1)(n) (n + 1 – i) * yi
Variables:
- GI is the Gini Index
- n is the number of data points
- yi is the i-th data point in ascending order
To calculate the Gini Index, first sort the data points in ascending order. Then compute the sum of all data points, ฮฃ(i=1)(n) yi. Next, compute the weighted sum ฮฃ(i=1)(n) (n + 1 – i) * yi. Finally, substitute these into GI = 1 + 1/n – (2 / (n * ฮฃ yi)) * ฮฃ (n + 1 – i) * yi. With a positive total, this uncorrected empirical formula ranges from 0 (equal values) to 1 โ 1/n for n observations. An all-zero total is undefined; no sample-size correction is applied.
Weighted Gini of a Decision-Tree Split
Choose Weighted Gini of a decision-tree split to evaluate a proposed split. Enter one child node per line, with the count for each class in the same column on every line. Use zero for a class absent from a child. Each child must contain at least one item. The calculator displays each child’s impurity and weights it by that child’s share of the total item count.
For child j, nj = ฮฃk cjk, pjk = cjk/nj, and Gj = 1 โ ฮฃk pjk2. With N = ฮฃj nj, weighted Gini = ฮฃj (nj/N) ร Gj. The parent counts are the column sums of all children. Gini gain = parent impurity โ weighted Gini; a larger gain means a greater reduction in class mixing for this split. This is a classification impurity measure, separate from the income-inequality coefficient. The tool evaluates supplied child nodes; it does not find a split threshold or accept survey weights.
How to Calculate Gini Index?
The following steps outline how to calculate the Gini Index.
- First, determine the number of data points (n).
- Next, arrange the data points in ascending order.
- Next, calculate the sum of all the data points (ฮฃ(i=1)(n) yi).
- Next, calculate the sum of (n + 1 – i) * yi for each data point.
- Next, calculate GI = 1 + 1/n – (2 / (n * ฮฃ(i=1)(n) yi)) * ฮฃ(i=1)(n) (n + 1 – i) * yi.
- Finally, report the Gini Index (GI).
- After inserting the variables and calculating the result, check your answer with the calculator above.
Example Problem :
Use the following variables as an example problem to test your knowledge.
Number of data points (n) = 5
Data points (yi) in ascending order: 1, 2, 3, 4, 5. Their total is 15 and the Gini coefficient is 0.266667 (Gini index 26.6667 on a 0โ100 scale).
