#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🌳 FREE · GINI AND ENTROPY

Gini Impurity Calculator: Which Split Is Best?

Enter class counts per branch, or paste a dataset, to see how much each split purifies the data.

  • 📉 Gini gain
  • ℹ️ Information gain
  • 🏆 Best feature

How to use the Gini Impurity Calculator

  1. 1. Choose your inputEnter class counts for each branch of one split, or paste a whole dataset.
  2. 2. Name the classesGive the class names so the table reads clearly.
  3. 3. CalculateSee Gini and entropy for every node, the weighted values and the gain.

The formulas

For a node with class shares p₁, p₂, …, Gini impurity is 1 − Σ pᵢ² and entropy is −Σ pᵢ log₂ pᵢ. Both are 0 for a pure node and largest when the classes are evenly mixed. A split's quality is the parent's impurity minus the weighted average of its children's impurity, where each child is weighted by its share of the samples. With entropy this drop is called information gain. C4.5's gain ratio divides information gain by the split's own entropy, which penalises splits with many small branches.

Worked example

Split 20 people (12 Yes, 8 No) by age: under 30 (2 Yes, 6 No), 30–50 (7, 1) and over 50 (3, 1). The parent Gini is 1 − 0.6² − 0.4² = 0.4800. The children score 0.3750, 0.2188 and 0.3750, and weighted by 8, 8 and 4 of the 20 samples they average 0.3125. The Gini gain is 0.1675, the information gain is 0.2668 bits and the gain ratio is 0.1753. In dataset mode, the play-tennis table's best first split is Outlook, with a Gini gain of 0.1163.

Tips

  • Gini and entropy usually pick the same split; Gini is a little faster to compute.
  • Dataset mode splits on every value of a column (as ID3 and C4.5 do). scikit-learn's trees split numbers in two at a threshold, so results can differ for numeric columns.
  • Information gain favours columns with many values, such as IDs; gain ratio corrects for that.

Frequently asked questions

What's the maximum Gini impurity?

1 − 1/k for k equally mixed classes: 0.5 for two classes, 0.667 for three.

Is my data uploaded?

No. All the counting happens in your browser.

Is the Gini impurity calculator free?

Yes. You can open the Gini impurity calculator and enter everything without signing up. When you calculate a split for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.

More free tools

See all free tools