A node has 10 samples, 6 positive and 4 negative. A split sends 5 samples left (4 positive, 1 negative) and 5 right (2 positive, 3 negative). What is the Gini impurity of the parent and of the two children, and what is the Gini gain of the split?

Supervised learning, Decision trees: Gini
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you can compute Gini impurity for a node and the weighted decrease from a split, as CART does.

Key idea

Gini =1−∑kpk2. The gain of a split is parent impurity minus the sample-weighted average of the children's impurities.

Steps

  1. Parent: p=(0.6,0.4), so Gini =1−0.36−0.16=0.48.
  2. Left child: p=(0.8,0.2), so Gini =1−0.64−0.04=0.32.
  3. Right child: p=(0.4,0.6), so Gini =1−0.16−0.36=0.48.
  4. Weight the children by their sizes: 510(0.32)+510(0.48)=0.16+0.24=0.40.
  5. Gini gain =0.48−0.40=0.08. CART tries every split and picks the one with the largest gain.

Common mistakes

How long your answer should be

4–5 lines of arithmetic.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: What is the difference between multiclass and multilabel classification, and how do the output activation, the loss and the prediction rule differ for a neural or linear model with L outputs? What are three ways to reduce multilabel to simpler problems?
Next in Supervised learning: A node has 12 samples, 6 of each class. Attribute ID takes 12 distinct values (one per sample). Attribute B splits the samples into two groups of 6: (5 positive, 1 negative) and (1 positive, 5 negative). Compute the information gain and the gain ratio of both attributes. Which one does ID3 pick and which does C4.5 pick, and why?