Calculate an empirical Gini coefficient from equally weighted non-negative values, or calculate Gini impurity from class counts. These are different measures.
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) y_i)) * Σ_(i=1)^(n) (n + 1 – i) * y_i
Variables:
- GI is the Gini Index
- n is the number of data points
- y_i 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) y_i. Next, compute the weighted sum Σ_(i=1)^(n) (n + 1 – i) * y_i. Finally, substitute these into GI = 1 + 1/n – (2 / (n * Σ y_i)) * Σ (n + 1 – i) * y_i. 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.
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) y_i).
- Next, calculate the sum of (n + 1 – i) * y_i for each data point.
- Next, calculate GI = 1 + 1/n – (2 / (n * Σ_(i=1)^(n) y_i)) * Σ_(i=1)^(n) (n + 1 – i) * y_i.
- 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 (y_i) 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).
