Exercises — Entropy and information gain
Recall One-line reminders of the tools you need
- Entropy: (units = bits, because ).
- Binary entropy: .
- Convention: .
- Information gain: .
- Gini impurity: .
- SplitInfo: ; Gain Ratio . ⚠️ Edge case: Gain Ratio is undefined when — see below.
Handy log values you will reuse (all base 2):
Visual warm-up (read before the exercises)
The whole page rests on four pictures. Meet them once so every exercise below is "just reading a graph you already understand".



Level 1 — Recognition
Exercise 1.1
Which of these class counts gives entropy exactly bits? (a) 5 Yes, 5 No (b) 8 Yes, 0 No (c) 3 Yes, 1 No.
Recall Solution
Entropy is only when one class has probability 1 (perfectly pure) — the ends of the red curve in Figure s01.
- (a) 50/50 → bit, not 0.
- (b) all Yes → , . ✅
- (c) mixed → .
Answer: (b).
Exercise 1.2
A binary node is at its maximum entropy. What is (fraction of positives) and what is ?
Recall Solution
Binary entropy peaks at the top of the hump in Figure s01, where both classes are equally likely: . Answer: , bit.
Level 2 — Application
Exercise 2.1
Compute for a node with 3 Yes, 1 No.
Recall Solution
. Now , and . Answer: bits. (On Figure s01 this is the height of the red curve at .)
Exercise 2.2
Compute for a 3-class node: 2 A, 2 B, 4 C (8 total).
Recall Solution
. , : Answer: bits. (Note: >1 is fine — with 3+ classes entropy can exceed 1 bit.)
Exercise 2.3
Compute the Gini impurity for the same node (2 A, 2 B, 4 C).
Recall Solution
Answer: . (Log-free, hence cheaper than entropy — the black curve in Figure s03; see Gini Impurity.)
Level 3 — Analysis
Exercise 3.1
Parent node: 10 Yes, 10 No (20 examples). Split on attribute :
- Left (12): 9 Yes, 3 No
- Right (8): 1 Yes, 7 No
Compute the information gain .
Recall Solution
Step 1 — parent. 10/10 → bit.
Step 2 — children. Left: → this is the same distribution as Exercise 2.1: Right: , . , .
Step 3 — weighted child entropy. The weights are the child widths from Figure s02:
Step 4 — gain. Answer: bits — a genuinely useful split (both children lean strongly one way).
Exercise 3.2
Two candidate splits on the same parent ( bit, 20 examples):
- Split P: two children each 50/50 (10 and 10).
- Split Q: children {9 Yes, 3 No} (12) and {1 Yes, 7 No} (8) — the split from 3.1.
Without heavy computation, which has higher gain, and why?
Recall Solution
Split P: each child is 50/50 → each → weighted after . Split Q: weighted after (from 3.1). Split Q wins. Reasoning without arithmetic: Split P produces children just as messy as the parent — it separated nothing. Split Q pushed each child toward a majority class, removing uncertainty. Gain measures how much the mess dropped, not how the examples were counted.
Level 4 — Synthesis
Exercise 4.1
An ID column gives every one of 6 examples (3 Yes, 3 No) its own value, so 6 children of size
- Compute (a) , (b) SplitInfo, (c) Gain Ratio. Then explain why raw is misleading here.
Recall Solution
(a) . Parent 3/3 → . Each child has 1 example → pure → . Weighted after .
(b) SplitInfo. Six equal children, each : bits.
(c) Gain Ratio.
Why raw misleads: an ID splits data into pure singletons, so hits its max of — but the tree learned nothing generalisable (a new example has a brand-new ID). Gain Ratio divides by SplitInfo, which is huge for many-valued splits, penalising the fake gain. This is why C4.5 uses Gain Ratio.
Exercise 4.2 (edge case)
When is Gain Ratio undefined, and how does C4.5 handle it? Give the smallest concrete example.
Recall Solution
Gain Ratio blows up (division by zero) exactly when . Since is itself an entropy of the child-size distribution, it is iff all data fall into a single branch — i.e. the split has only one non-empty child.
Smallest example: an attribute that takes the same value for all 6 examples. Then there is one child with :
The critical subtlety — it's actually , not . A single-branch split also removes no mess, because the one child is identical to the parent: So both numerator and denominator vanish: , an indeterminate form — not a "big number", not "infinity", simply undefined. Students who imagine a huge Gain Ratio here are wrong in the opposite direction; there is nothing to gain at all.
How C4.5 handles it: such a split is simply rejected / skipped — a candidate that leaves everything in one branch is never chosen. In practice C4.5 only considers attributes whose is at least the average gain first; a zero- (hence ) candidate fails that screen and never reaches the division.
Exercise 4.3
Refer to Figure s01. Point marks the weighted child entropy (on the straight chord); point marks the true entropy of the mixed parent (on the curve). Explain, using the figure, why information gain can never be negative.
Recall Solution
The red curve is binary entropy ; it is concave (bulges upward). Look at the figure:
- The two children of a split sit at their own -values on the curve.
- The parent's is the weighted average of the children's -values — it lands at on the curve (the true entropy).
- The weighted average of the two children's entropies lands at , which is on the straight dashed chord below the curve.
Because the curve is concave, the chord is always at or below the curve: . So
\;\Longrightarrow\; IG = Y - X \ge 0.$$ Splitting can only remove uncertainty (or leave it unchanged), never add it.Level 5 — Mastery
Exercise 5.1 (full split competition)
Parent: 14 examples, 9 Yes, 5 No ( bits). Two candidate attributes:
- Outlook (3 values):
- Sunny (5): 2 Yes, 3 No
- Overcast (4): 4 Yes, 0 No
- Rain (5): 3 Yes, 2 No
- Humidity (2 values):
- High (7): 3 Yes, 4 No
- Normal (7): 6 Yes, 1 No
Compute for both and decide which the tree picks.
Recall Solution
Parent: .
--- Candidate 1: Outlook ---
Children.
- Sunny (2/5, 3/5): .
- Overcast (4/0): pure → .
- Rain (3/5, 2/5): same distribution as Sunny by symmetry → .
Weighted after (widths from Figure s02):
--- Candidate 2: Humidity ---
Children.
- High (3/7, 4/7): .
- Normal (6/7, 1/7): .
Weighted after:
--- Decision --- The tree splits on Outlook. Its pure "Overcast" child (entropy 0) is what makes it shine — it becomes a leaf immediately, removing more mess than Humidity's two still-mixed children.
Exercise 5.2 (base-invariance of ranking)
Recompute from 5.1 using natural log instead of (units become nats). Does the choice of feature change?
Recall Solution
To convert an entropy measured in bits into nats, use , so bits → nats means multiply by (the nat is a larger unit, so the numeric value shrinks). Because is a linear combination of entropies, it scales by the same factor : Likewise nats. The numbers shrink but the ordering is unchanged (), so the tree still picks Outlook. Ranking of splits is base-independent; only the units differ.
(If you instead went from nats back to bits you would multiply by — the inverse conversion. Here we go bits→nats, hence the factor .)
Recap
Recall What changes across levels?
L1 asks what the definitions say. L2 asks you to plug in numbers. L3 makes you compare splits. L4 exposes the high-cardinality bias, the SplitInfo=0 () edge case, and the concavity guarantee. L5 runs a full multi-feature competition and proves base-invariance. The single formula carries all of it.
Connections
- Parent: Entropy and Information Gain
- Decision Trees — these gains choose each node's question.
- ID3 and C4.5 Algorithms — ID3 uses , C4.5 uses Gain Ratio (Exercises 4.1–4.2).
- Gini Impurity — the log-free cousin from Exercise 2.3 and Figure s03.
- Overfitting and Pruning — the ID-column trap in 4.1 is exactly why pure leaves overfit.