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?

Supervised learning, Decision trees: gain ratio
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you see why information gain favours many-valued attributes and how the gain ratio corrects it.

Key idea

Gain ratio =GainSplitInfo, where SplitInfo=−∑vnvnlog⁡2nvn is the entropy of the split sizes. It penalises attributes that cut the data into many small pieces.

Steps

  1. Parent entropy: H=1 bit, because the classes are 6 and 6.
  2. Attribute ID: each child has one sample, so is pure and has entropy 0. Gain =1−0=1. SplitInfo =log⁡212≈3.585. Gain ratio ≈1/3.585=0.279.
  3. Attribute B: each child has proportion 5/6 and 1/6. Entropy =−56log⁡256−16log⁡216≈0.219+0.431=0.650. Gain =1−0.650=0.350.
  4. SplitInfo of B =−2⋅12log⁡212=1. Gain ratio =0.350/1=0.350.
  5. ID3 uses the gain, so it picks ID (1.0 against 0.35). This is useless: a tree on an ID column memorises the training set and cannot generalise.
  6. C4.5 uses the gain ratio, so it picks B (0.350 against 0.279). Real C4.5 also keeps only attributes whose gain is at least the average, to stop a tiny SplitInfo inflating the ratio. Here the average gain is (1+0.35)/2=0.675, which would wrongly keep only ID, so this toy example uses the plain gain-ratio rule to show the idea.

Common mistakes

How long your answer should be

Half a page; 4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: 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?
Next in Supervised learning: Take the Gaussian (RBF) kernel k(x,z)=exp⁡ ⁣(−(x−z)22) on the 1-D points x=0,1,3. Write the Gram matrix. What happens to the Gram matrix when the width is made very small and when it is made very large, and what does that mean for an SVM?