Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Twenty questions, asked well
A decision tree classifies by asking questions: “Is the outlook sunny? Is the humidity high?” Good trees ask the most useful question first, the one that leaves you least uncertain about the answer. ID3 measures uncertainty with entropy (in bits) and picks, at every step, the question whose answer removes the most entropy, the largest information gain. It keeps asking until each group of examples agrees on one label.
- — overcast → yes (4)
- — rain wind? gain 0.971
- — strong → no (2)
- — weak → yes (3)
- — sunny humidity? gain 0.971
- — high → no (3)
- — normal → yes (2)
Decision trees are readable rules: an operator can follow “if mode = safe and heater = on then fault” without any software. ID3 is the ancestor of C4.5 and CART, which in turn are the building blocks of random forests and gradient boosting, the most widely used tabular models in industry.
- 1. ID3 splits on the attribute with the largest…
- 2. ID3 stops growing a branch when…
- 3. In the demo, a day-ID attribute…
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Computing gains by hand
Entropy of a set with class proportions pᵢ: H = −Σ pᵢ log₂ pᵢ. With 9 “yes” and 5 “no”:
H = −(9/14)·log₂(9/14) − (5/14)·log₂(5/14) = 0.410 + 0.530 = 0.940 bits.
Information gain of attribute A is the parent entropy minus the size-weighted child entropies:
Gain = H(S) − Σ over values v of (|S_v|/|S|)·H(S_v).
Outlook.
- sunny: 2 yes, 3 no, so H = 0.971.
- overcast: 4 yes, 0 no, so H = 0.
- rain: 3 yes, 2 no, so H = 0.971.
- Weighted child entropy: (5/14)·0.971 + 0 + (5/14)·0.971 = 0.694. Gain = 0.940 − 0.694 = 0.247.
Humidity.
- high: 3 yes, 4 no, so H = 0.985.
- normal: 6 yes, 1 no, so H = 0.592.
- Weighted child entropy: 0.5·0.985 + 0.5·0.592 = 0.789. Gain = 0.152.
Wind gives 0.048 and temperature 0.029, so outlook becomes the root. Its overcast branch is already pure (“yes”). Recursing on the sunny days, humidity separates them perfectly; on the rainy days, wind does.
The steps in plain English:
- If every example at this node has the same label, or no attributes are left, make a leaf with the majority label.
- Otherwise compute the information gain of each remaining attribute.
- Split on the best one, with one branch per value.
- Recurse on each branch, without reusing that attribute.
- 1. Entropy of a 50/50 split?
- 2. Entropy of a pure node?
- 3. Gain of outlook on the 14-day table?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.The algorithm and its properties
Information gain is mutual information. Gain(S, A) = H(Y) − H(Y | A) = I(Y; A), computed on the examples at the node.
ID3 search. ID3 is a greedy, top-down, hill-climbing search through the space of trees, with no backtracking. Its preference (“inductive bias”) is for short trees that place high-gain attributes near the root. That is an Occam’s-razor bias, applied greedily and not guaranteed to find the smallest tree (finding it is NP-hard; Hyafil and Rivest, 1976).
Limitations, and who fixed them.
| Limitation | Fix |
|---|---|
| Categorical attributes only | C4.5 thresholds on continuous features |
| Bias toward many-valued attributes | gain ratio (C4.5), binary splits (CART) |
| Grows until pure, so it overfits noise | χ² pre-pruning (ID3), error-based pruning (C4.5), cost-complexity pruning (CART) |
| No missing-value handling | fractional examples (C4.5), surrogate splits (CART) |
Cost. Each level scans all examples for all attributes, so building costs O(n·p·depth).
from sklearn.tree import DecisionTreeClassifier # CART, not ID3; criterion="entropy" uses information gain
clf = DecisionTreeClassifier(criterion="entropy").fit(pd.get_dummies(X), y)- 1. Information gain equals…
- 2. ID3's search is…
- 3. Finding the smallest consistent tree is…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Why many-valued attributes win. Splitting into more groups can only lower or keep the weighted child entropy. With finite samples, an attribute with many values creates small groups that are pure by chance. An attribute unique per example (an ID) yields all-pure leaves and gain H(S), the maximum. The gain estimate is biased upward roughly in proportion to (values − 1)(classes − 1)/n: 2n·ln 2 times the empirical gain is the G-statistic, approximately χ²-distributed with that many degrees of freedom under independence.
The χ² view. That approximation suggests testing each split’s significance, which Quinlan’s ID3 did. A significance test automatically demands more evidence from many-valued attributes. Exercise 2 shows it works when used as a filter (choose the best significant attribute), but fails if you first pick the best-gain attribute and then test it: the serial number wins, fails the test, and growth stops at the root.
Overfitting. Growing until pure fits label noise, and the tree size grows roughly linearly with n on noisy data. Pruning is essential (see the pruning page).
Interview questions.
- Why is a customer-ID column dangerous for ID3? It gets the maximum information gain and memorises the training set. Drop identifiers, or use gain ratio or binary splits.
- How does ID3 differ from CART? ID3 uses categorical multiway splits, information gain and no pruning. CART uses binary splits on any feature type, Gini or variance, and cost-complexity pruning.
- 1. Under independence, 2n·ln 2 × gain is approximately…
- 2. An ID attribute's information gain is…
- 3. Growing until pure on noisy data…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.When a serial number hijacks the tree
History.
- Hunt’s Concept Learning System (1966) introduced top-down induction of decision trees.
- Quinlan developed ID3 (1979 at Stanford, published 1986 in Machine Learning) using Shannon’s entropy.
- Breiman, Friedman, Olshen and Stone’s CART (1984) arrived independently with binary splits and pruning.
- Quinlan’s C4.5 (1993) and C5.0 extended ID3 and became among the most cited algorithms in ML. C4.5 was #1 in the 2008 “top 10 algorithms in data mining” survey.
Exercise 1.
- H(play) = 0.9403. The gains are outlook 0.2467, humidity 0.1518, wind 0.0481 and temperature 0.0292.
- The tree splits on outlook, then humidity under sunny and wind under rain, and fits all 14 days.
- A day-ID attribute would get gain 0.9403, the maximum.
Exercise 2. Setup: fault-log data where the label depends on mode, heater and bus with 10% label noise, plus two irrelevant 3-valued attributes and a 40-valued serial-number “unit”. n = 150 training rows, a clean test set, 10 repetitions.
| Variant | test accuracy | unit at root | tree size (nodes) |
|---|---|---|---|
| ID3 (information gain) | 0.630 | 100% | 121 |
| gain ratio (C4.5’s criterion) | 0.798 | 30% | 115 |
| ID3 + χ² significance filter | 0.949 | 0% | 15 |
| ID3 never shown “unit” | 0.899 | (n/a) | 75 |
- Plain ID3 put the serial number at the root in every run. With 40 values and 150 rows, its groups are tiny and look informative. Accuracy fell to 0.63.
- Gain ratio helped (0.80) but still chose “unit” at the root 30% of the time. It also used it somewhere in every tree.
- The χ² filter fixed both problems. It never split on “unit”, and by refusing insignificant splits it also stopped fitting label noise. It produced a 15-node tree that beat even unpruned ID3 without “unit” (0.949 against 0.899).
- Lesson: remove identifiers, and always control tree growth with a statistical test or pruning.
ID3 in AI, robotics and aerospace
- Rule extraction for fault diagnosis: readable if-then rules from labelled anomaly logs.
- Expert-system knowledge acquisition (the original motivation: chess endgames and medical diagnosis).
- Building block: every tree ensemble starts from this greedy split search.
- Feature screening: information gain ranks categorical sensor flags by relevance.
References
- J. R. Quinlan (1986). “Induction of decision trees.” Machine Learning 1(1).
- T. M. Mitchell (1997). Machine Learning, chapter 3. McGraw-Hill.
- E. B. Hunt, J. Marin, P. J. Stone (1966). Experiments in Induction. Academic Press.
- L. Hyafil, R. L. Rivest (1976). “Constructing optimal binary decision trees is NP-complete.” Information Processing Letters 5(1).
- X. Wu et al. (2008). “Top 10 algorithms in data mining.” Knowledge and Information Systems 14.