Gini Impurity Calculator for Machine Learning

Analyse node purity, compare candidate splits, test numeric thresholds, evaluate categories, and export detailed Gini calculations for practical decision-tree learning and modelling tasks today.

Calculation Result

Choose a mode, enter values, then calculate.
Primary result
Gini gain
Samples
Interpretation

Detailed calculation

No calculation has been completed.

Calculator Modes

Use one count per class, separated by commas.
Format: Child name: class1, class2, class3. Add multiple children.
Format: split label | left counts | right counts.
Format: feature,label,optional weight. A header row is optional.

Formula Used

Gini(node) = 1 − Σ pᵢ²
Weighted Gini(split) = Σ (Nⱼ ÷ N) × Gini(childⱼ)
Gini gain = Gini(parent) − Weighted Gini(split)

Zero impurity means one class fills the node. Lower split impurity usually indicates a stronger decision rule. Larger Gini gain means the split removes more uncertainty.

How to Use

  1. Select the calculation mode matching your decision-tree task.
  2. Enter valid class counts, probabilities, splits, or dataset rows.
  3. Choose precision, weighting, missing-value, and threshold settings.
  4. Press the calculation button and review ranked results.
  5. Copy, print, or export the detailed calculation.

Example Data

ScenarioInputExpected meaning
Pure node50, 0Gini equals zero.
Balanced binary node50, 50Gini equals 0.5.
Balanced three-class node30, 30, 30Gini approaches 0.6667.
Useful splitParent 50,50; children 40,10 and 10,40Weighted impurity decreases.

Gini Impurity and Entropy

Both measures evaluate class mixing inside decision-tree nodes. Gini uses squared probabilities and avoids logarithms. Entropy often changes more sharply near rare classes.

MeasureFormulaTypical use
Gini impurity1 − Σpᵢ²CART classification trees
Entropy−Σpᵢlog₂pᵢInformation gain trees
Misclassification error1 − max(pᵢ)Simple node error estimate

Frequently Asked Questions

What does Gini impurity measure?

It measures class mixing within a classification node. Zero means every sample shares one class. Larger values indicate a more mixed node.

Is a lower Gini value better?

Lower impurity usually means a purer decision-tree node. Split comparisons should use weighted child impurity. The smallest valid value often wins.

What is the maximum binary Gini impurity?

The maximum binary value is 0.5. It occurs with equal class probabilities. Multiclass maximums can exceed this value.

How is Gini gain calculated?

Subtract weighted child impurity from parent impurity. Positive gain indicates improved class separation. Larger gains indicate stronger impurity reduction.

Can this calculator handle multiclass data?

Yes, node and split modes accept many classes. Dataset mode detects labels automatically. All detected probabilities contribute to impurity.

How are sample weights used?

Dataset weights change class totals and child sizes. Single-node class weights adjust effective class counts. Negative or zero weights are rejected.

How are missing feature values handled?

You can exclude or assign missing rows. Categorical analysis can keep a separate category. The chosen method affects every candidate split.

Why can two splits share the same Gini?

Different splits can create equivalent class proportions. Their weighted impurities will then match. Secondary rules may choose between them.

Does the best local split guarantee the best tree?

No, tree construction commonly uses greedy decisions. A strong local split may limit later branches. Validation and pruning remain important.

Related Calculators

Decision Tree Entropy CalculatorInformation Gain CalculatorDecision Tree Split CalculatorRandom Forest Voting CalculatorGradient Boosting Prediction CalculatorAdaBoost Weight CalculatorXGBoost Gain CalculatorBagging Sample CalculatorDecision Tree Splitting QuizGini Impurity Quiz

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.