Calculate an empirical Gini coefficient from equally weighted non-negative values, or calculate Gini impurity from class counts. These are different measures.

Separate values with commas, spaces or new lines. Use a decimal point; omit thousands separators. Maximum 10,000 values.


Related 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.


  1. First, determine the number of data points (n).
  2. Next, arrange the data points in ascending order.
  3. Next, calculate the sum of all the data points (Σ_(i=1)^(n) y_i).
  4. Next, calculate the sum of (n + 1 – i) * y_i for each data point.
  5. Next, calculate GI = 1 + 1/n – (2 / (n * Σ_(i=1)^(n) y_i)) * Σ_(i=1)^(n) (n + 1 – i) * y_i.
  6. Finally, report the Gini Index (GI).
  7. 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).