liveBook · Manning

Gini impurity

Also called Gini index

Gini impurity is a measure of class-label heterogeneity in a set or decision-tree node, calculated from the proportions of its classes.

How 9 Manning books explain it

Grokking Machine Learning

A decision-tree impurity measure that quantifies the heterogeneity of class labels within a node.

How it is used
Selects classification-tree questions by favoring splits that leave less-mixed groups of labels.
How deep it goes
Derives the probability formula from two random draws and works through child-group averages, including weighting unequal groups.
Examples
Uses colored balls, app recommendations, age cutoffs, and a credit-card-fraud exercise to make split comparisons concrete.
What you can do after
Build it from scratch by calculating class shares, weighting child-group impurities, and selecting a lower-impurity split.

Read how Grokking Machine Learning explains Gini impurity →

Grokking Machine Learning, Second Edition

The Gini index is a decision-tree impurity measure based on the probability of misclassification under the label distribution at a node.

How it is used
Guides decision-tree classification toward questions that create purer label groups.
How deep it goes
Derives the probability formula, compares weighted splits, and applies thresholds for continuous features.
Examples
Uses colored balls, app recommendations, numeric ages, spatial labels, and credit-card fraud transactions.
What you can do after
Apply it to compare candidate decision-tree splits and select lower-impurity branches.

Read how Grokking Machine Learning, Second Edition explains Gini impurity →

Statistics Every Programmer Needs

Gini impurity is a node-impurity measure equal to the probability of misclassifying an observation when labels are assigned according to the node's class distribution.

How it is used
Ranks candidate classification-tree splits by how well their branches separate class labels.
How deep it goes
Works through class counts and size-weighted impurity for categorical and numeric splits, while treating entropy mainly as an alternative.
Examples
Uses fourth-down conversion counts grouped by play type and by a distance-to-go threshold.
What you can do after
Apply it via scikit-learn classifiers and calculate weighted impurity to compare candidate root splits.

Read how Statistics Every Programmer Needs explains Gini impurity →

Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

Gini impurity is the probability of misclassifying an element labeled according to the class distribution of its subset.

How it is used
Guides classification-tree split selection by favoring child subsets with more homogeneous target labels.
How deep it goes
Defines the misclassification probability and demonstrates threshold scoring, but stops short of a mathematical derivation.
Examples
Uses Airbnb price-range prediction, latitude thresholds, exhaustive candidate search, and 256-bin histogram candidates.
What you can do after
Build a split-scoring routine from scratch and compare exhaustive threshold search with histogram-based candidates.

Read how Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI explains Gini impurity →

Grokking AI Algorithms, Second Edition

The Gini index is an impurity measure that quantifies the likelihood of incorrect class assignment in a labeled dataset.

How it is used
Measures dataset impurity while training decision trees and comparing candidate splits.
How deep it goes
Defines impurity, contrasts pure and mixed datasets, and implements the calculation without theoretical proof.
Examples
Uses Perfect and Okay diamonds, including balanced and completely pure bags, to illustrate impurity values.
What you can do after
Apply it via Python to calculate impurity and compare candidate decision-tree splits.

Read how Grokking AI Algorithms, Second Edition explains Gini impurity →

Build AI Drug Discovery Pipelines

Gini impurity measures the expected misclassification rate when class labels are randomly assigned according to their distribution within a node.

How it is used
Guides decision-tree splits while classifying molecules as cytochrome P450 inhibitors or noninhibitors.
How deep it goes
Defines node impurity, class-dependent bounds, and weighted split evaluation, but stops short of broader tree optimization.
Examples
Uses molecular weight, logP, CYP inhibition labels, node counts, and a depth-two tree visualization.
What you can do after
Apply it via scikit-learn to interpret tree nodes and compare candidate feature splits.

Read how Build AI Drug Discovery Pipelines explains Gini impurity →

Machine Learning Algorithms in Depth

The Gini index is an impurity measure for evaluating the heterogeneity of class labels in a set or node.

How it is used
Evaluates candidate CART partitions and guides feature-threshold selection toward purer classification leaves.
How deep it goes
Explains class proportions, purity, expected error, and a threshold example, while contrasting entropy as an alternative objective.
Examples
Uses a five-point one-dimensional dataset, threshold 2, pure left leaf, and mixed right leaf.
What you can do after
Evaluate candidate classification splits and implement the surrounding CART search procedure.

Read how Machine Learning Algorithms in Depth explains Gini impurity →

Fight Fraud with Machine Learning

Gini impurity is a measure of the class mixture within a decision-tree node, with zero indicating a node containing a single class.

How it is used
Interprets class mixing inside decision-tree nodes while explaining fraud decisions in random-forest models.
How deep it goes
Defines binary and multi-class calculation, node interpretation, and impurity-reducing splits.
Examples
Uses genuine and fraudulent transaction counts, transfer-feature splits, and plotted tree nodes as concrete examples.
What you can do after
Evaluate and understand class composition and split behavior when inspecting decision trees and random-forest visualizations.

Read how Fight Fraud with Machine Learning explains Gini impurity →

Timeless Algorithms, The Foundational Ideas

Gini impurity measures the probability of misclassifying an observation when its class is assigned randomly according to the class distribution in a node.

How it is used
Evaluates candidate decision-tree splits by how well they partition outcomes into homogeneous groups.
How deep it goes
Contrasts impurity with entropy, noting similar split preferences and computational simplicity.
Examples
Uses loan-approval outcomes to illustrate nodes with balanced or dominant classes in the discussion of homogeneous splits.
What you can do after
Evaluate candidate decision-tree splits alongside entropy, expecting similar trees and little difference in predictive performance.

Read how Timeless Algorithms, The Foundational Ideas explains Gini impurity →

Also covered in

What to know first

Related concepts

Questions about Gini impurity

What is Gini impurity?

Gini impurity is a measure of class-label heterogeneity in a set or decision-tree node, calculated from the proportions of its classes.

Which Manning books explain Gini impurity?

Grokking Machine Learning, Grokking Machine Learning, Second Edition, Statistics Every Programmer Needs, Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI, Grokking AI Algorithms, Second Edition, Build AI Drug Discovery Pipelines, Machine Learning Algorithms in Depth, Fight Fraud with Machine Learning and 1 more.

What should I know before learning Gini impurity?

Manning books that teach Gini impurity usually introduce accuracy, linear regression, classifier and evaluation criterion first.

What is the difference between Gini impurity and entropy?

Gini impurity is a measure of class-label heterogeneity in a set or decision-tree node, calculated from the proportions of its classes. Entropy is an information-theoretic measure of uncertainty in a probability distribution, defined as the expected value of the negative logarithm of outcome probability.

What is Gini impurity also called?

Gini impurity is also called Gini index.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.