Calculators

Gini Impurity Calculator

Calculate Gini impurity from class counts, weights or probabilities with automatic normalization, privately in your browser.

Enter one non-negative count or weight per class, separated by spaces, commas or semicolons. Weights are normalized automatically. Use 1–10000 values and at most 200000 characters. Nonzero weights must be between 1e-100 and 1e100; at least one must be positive. Calculation runs locally in your browser.

Your Gini impurity will appear here.

How Gini impurity works

Gini impurity is 1 − Σpᵢ², where pᵢ is each class weight divided by the total weight. It is the probability that two independent draws with replacement have different class labels. For weights 3 and 1, probabilities are 0.75 and 0.25 and impurity is 0.375. A pure single-class distribution gives 0. With k entered classes the maximum is 1 − 1/k, reached by equal weights. Zero-weight classes count toward the entered class count but do not change impurity; adding absent classes changes the theoretical maximum, not the measured impurity. This is the decision-tree impurity measure, not the income-inequality Gini coefficient, entropy, or a split gain. Enter 1 to 10000 non-negative decimal values separated by spaces, commas or semicolons, up to 200000 characters. Scientific notation is accepted; commas separate values rather than thousands. Nonzero weights must be between 1e-100 and 1e100, and at least one must be positive. Scaling and pair-product summation avoid overflow and reduce cancellation near pure distributions. Results use browser floating-point arithmetic and up to 12 significant digits. All processing stays in your browser.

Frequently Asked Questions

Everything you need to know about this tool, how it works, and privacy.

What is the Gini impurity formula?

Gini impurity is 1 − Σpᵢ², using normalized class probabilities. For class counts 3 and 1, the result is 0.375.

Must weights sum to one?

No. Counts or non-negative weights are normalized automatically. At least one class must have positive weight.

What is the range?

For k entered classes the range is 0 to 1 − 1/k. Equal weights attain the maximum; one positive class gives zero.

Is this the Gini coefficient?

No. This measures class impurity, often used in decision trees. It does not calculate income inequality or the gain from a tree split.

How are zeros and small weights handled?

Zero weights do not change impurity. Nonzero weights must be between 1e-100 and 1e100. Pair-product summation reduces cancellation near pure distributions; results show up to 12 significant digits.