Learning a tree of questions, chosen by how much each one tells you.
π Where this lives: decision trees are the model people actually deploy when the decision must be explained. A loan refusal, a medical triage category, a fraud flag β all need a reason a human can check, and a tree gives one by construction: you read the path from root to leaf. That is why trees and their ensembles remain the standard choice for tabular data in regulated settings, decades after fancier methods appeared. Search "decision tree interpretability tabular data gradient boosting".
What a decision tree is
A DECISION TREE is a tree in which
each INTERNAL NODE tests an attribute
each BRANCH corresponds to a value of that attribute
each LEAF assigns a classification
Classification proceeds by starting at the root and following
the branches matching the instance's attribute values until a
leaf is reached.
A TREE IS EQUIVALENT TO A SET OF RULES β one rule per path from
root to leaf, with the tests conjoined:
IF Outlook = Sunny AND Humidity = High THEN Play = No
IF Outlook = Overcast THEN Play = Yes
THAT EQUIVALENCE IS THE SOURCE OF THE INTERPRETABILITY, and it
connects trees directly to the rule-based knowledge of
ACtE0904 β except that the rules are INDUCED from data rather
than elicited from an expert. Decision-tree induction is
therefore the automated answer to the knowledge-acquisition
bottleneck.
THE PROBLEM DECISION-TREE LEARNING SOLVES: given a table of
labelled examples, build a tree that classifies them correctly
and generalises to new ones.
THE STANDARD ALGORITHM IS ID3 (Quinlan), with C4.5 and CART as
its descendants. It is a GREEDY, RECURSIVE, TOP-DOWN procedure:
function ID3(examples, attributes)
if all examples have the same class
return a leaf with that class
if attributes is empty
return a leaf with the majority class
A β the attribute with the HIGHEST INFORMATION GAIN
create a node testing A
for each value v of A
subset β examples with A = v
if subset is empty
attach a leaf with the majority class
else
attach ID3(subset, attributes β {A})
return the node
NOTE THAT IT IS GREEDY: it chooses the locally best attribute at
each node and NEVER BACKTRACKS. So it does not find the smallest
possible tree β that is NP-hard β but it finds a good one
cheaply. THE PREFERENCE FOR SHORT TREES IS ID3's INDUCTIVE BIAS,
and it is Occam's razor applied to trees.
Entropy and information gain, computed
THE ATTRIBUTE SELECTION MEASURE. This is the examinable
calculation, so it is worked in full.
ENTROPY measures the IMPURITY of a set of examples β how mixed
the classes are:
Entropy(S) = β Ξ£ pα΅’ logβ pα΅’
where pα΅’ is the proportion of examples in class i.
For two classes:
all one class β entropy 0 (perfectly pure)
50/50 split β entropy 1 (maximally impure)
any other split β between 0 and 1
WORKED SANITY CHECKS:
9 yes, 5 no out of 14:
p(yes) = 9/14 = 0.6429, p(no) = 5/14 = 0.3571
E = β0.6429 logβ 0.6429 β 0.3571 logβ 0.3571
= β0.6429 Γ (β0.6374) β 0.3571 Γ (β1.4854)
= 0.4098 + 0.5305 = 0.9403
4 yes, 0 no: E = 0 (pure β no further splitting needed)
3 yes, 3 no: E = 1 (maximally mixed)
INFORMATION GAIN is the REDUCTION in entropy achieved by
splitting on an attribute:
Gain(S, A) = Entropy(S) β Ξ£ (|Sα΅₯|/|S|) Β· Entropy(Sα΅₯)
v β values(A)
The second term is the WEIGHTED AVERAGE entropy of the
subsets. Gain is how much the split TELLS YOU β how much
uncertainty it removes.
THE FULL WORKED EXAMPLE β the standard weather dataset, 14 days,
9 yes and 5 no:
ββββββ¬βββββββββββ¬βββββββ¬βββββββββ¬βββββββββ¬βββββββ
β D β Outlook β Temp βHumidityβ Wind β Play β
ββββββΌβββββββββββΌβββββββΌβββββββββΌβββββββββΌβββββββ€
β 1 β Sunny β Hot β High β Weak β No β
β 2 β Sunny β Hot β High β Strong β No β
β 3 β Overcast β Hot β High β Weak β Yes β
β 4 β Rain β Mild β High β Weak β Yes β
β 5 β Rain β Cool β Normal β Weak β Yes β
β 6 β Rain β Cool β Normal β Strong β No β
β 7 β Overcast β Cool β Normal β Strong β Yes β
β 8 β Sunny β Mild β High β Weak β No β
β 9 β Sunny β Cool β Normal β Weak β Yes β
β 10 β Rain β Mild β Normal β Weak β Yes β
β 11 β Sunny β Mild β Normal β Strong β Yes β
β 12 β Overcast β Mild β High β Strong β Yes β
β 13 β Overcast β Hot β Normal β Weak β Yes β
β 14 β Rain β Mild β High β Strong β No β
ββββββ΄βββββββββββ΄βββββββ΄βββββββββ΄βββββββββ΄βββββββ
STEP 1 β the entropy of the whole set:
9 yes, 5 no β Entropy(S) = 0.9403
STEP 2 β the gain of each attribute.
OUTLOOK splits into three subsets:
Sunny : 5 examples, 2 yes 3 no β E = 0.971
Overcast : 4 examples, 4 yes 0 no β E = 0.000
Rain : 5 examples, 3 yes 2 no β E = 0.971
weighted = (5/14)(0.971) + (4/14)(0) + (5/14)(0.971)
= 0.3468 + 0 + 0.3468 = 0.6936
Gain(Outlook) = 0.9403 β 0.6936 = 0.2467
HUMIDITY splits into two:
High : 7 examples, 3 yes 4 no β E = 0.985
Normal : 7 examples, 6 yes 1 no β E = 0.592
weighted = (7/14)(0.985) + (7/14)(0.592) = 0.7885
Gain(Humidity) = 0.9403 β 0.7885 = 0.1518
WIND:
Weak : 8 examples, 6 yes 2 no β E = 0.811
Strong : 6 examples, 3 yes 3 no β E = 1.000
weighted = (8/14)(0.811) + (6/14)(1.000) = 0.8922
Gain(Wind) = 0.9403 β 0.8922 = 0.0481
TEMPERATURE:
Hot : 4, 2 yes 2 no β E = 1.000
Mild : 6, 4 yes 2 no β E = 0.918
Cool : 4, 3 yes 1 no β E = 0.811
weighted = (4/14)(1.000) + (6/14)(0.918) + (4/14)(0.811)
= 0.9111
Gain(Temperature) = 0.9403 β 0.9111 = 0.0292
STEP 3 β THE SUMMARY, and the choice:
Gain(Outlook) = 0.2467 β HIGHEST, so Outlook is the
Gain(Humidity) = 0.1518 root
Gain(Wind) = 0.0481
Gain(Temperature) = 0.0292
WHY OUTLOOK WINS IS VISIBLE IN THE NUMBERS: its Overcast
branch has entropy ZERO β four examples, all yes β so that
branch is finished immediately and becomes a leaf. No other
attribute produces a pure subset. INFORMATION GAIN REWARDS
SPLITS THAT SEPARATE THE CLASSES, and a pure branch is the
strongest possible separation.
STEP 4 β recurse on the impure branches:
Sunny branch (5 examples): compute gains among the
remaining attributes. Humidity splits it perfectly β
High β all No, Normal β all Yes β so the Sunny subtree
is one test.
Rain branch (5 examples): Wind splits it perfectly β
Weak β Yes, Strong β No.
THE RESULTING TREE:
Outlook
βββββββββββββΌββββββββββββ
Sunny Overcast Rain
β β β
Humidity YES Wind
ββββ΄βββ ββββ΄βββ
High Normal Weak Strong
β β β β
NO YES YES NO
FIVE LEAVES, THREE TESTS, and it classifies all 14 examples
correctly. Note that TEMPERATURE NEVER APPEARS β it carried
too little information, so the tree ignores it entirely.
THAT IS FEATURE SELECTION HAPPENING AS A BY-PRODUCT of
induction.
Problems, and the practical refinements
THE PROBLEMS WITH BASIC ID3, and the standard fixes:
1. OVERFITTING β the central danger
A tree grown until every leaf is pure fits the training data
perfectly, including its noise, and generalises badly. With
enough attributes a tree can memorise the training set.
THE FIXES:
PRE-PRUNING (early stopping): stop splitting when a node
has too few examples, or when the best gain is below a
threshold. Cheap, and risks stopping too early β a
split with low gain may enable a very good split below
it.
POST-PRUNING: grow the full tree, then remove subtrees
that do not improve accuracy on a VALIDATION SET.
Generally better, because it can see the consequences
of a split before deciding.
REDUCED-ERROR PRUNING and RULE POST-PRUNING (used by
C4.5) are the standard implementations.
2. INFORMATION GAIN FAVOURS ATTRIBUTES WITH MANY VALUES
A unique identifier β a student's roll number β splits the
data into singletons, every subset is pure, and the gain is
maximal. THE TREE IS PERFECT ON TRAINING DATA AND USELESS.
THE FIX: GAIN RATIO (C4.5), which divides the gain by the
intrinsic information of the split itself:
SplitInfo(S, A) = β Ξ£ (|Sα΅₯|/|S|) logβ (|Sα΅₯|/|S|)
GainRatio(S, A) = Gain(S, A) / SplitInfo(S, A)
SplitInfo is large for many-valued attributes, so the
ratio penalises them. A roll-number attribute has
SplitInfo = logβ 14 = 3.807 on our dataset, which
divides its gain down substantially.
ALTERNATIVE: the GINI INDEX, used by CART:
Gini(S) = 1 β Ξ£ pα΅’Β²
For 9 yes and 5 no: 1 β (9/14)Β² β (5/14)Β² = 1 β 0.4133 β
0.1276 = 0.4592. Gini and entropy usually choose the same
attribute and Gini is cheaper to compute β no logarithms.
3. CONTINUOUS ATTRIBUTES
ID3 assumes discrete values. For a continuous attribute,
sort the values and consider THRESHOLD splits (A < t),
choosing the threshold with the best gain. C4.5 does this
automatically.
4. MISSING VALUES
Options: assign the most common value; assign a value
probabilistically; or send the example down all branches
with fractional weight, which is C4.5's approach.
5. INSTABILITY (high variance)
A small change in the training data can produce a
completely different tree, because a different attribute
wins at the root and everything below changes. This is the
high-variance end of the biasβvariance trade-off.
THE FIX IS ENSEMBLES, and it is the reason trees are almost
never used singly in practice:
RANDOM FORESTS: train many trees on bootstrap samples of
the data, each considering a random subset of
attributes at each split, and vote. Averaging cancels
the variance.
GRADIENT BOOSTING: train trees in sequence, each
correcting the errors of the previous ones.
THESE REMAIN AMONG THE STRONGEST METHODS FOR TABULAR
DATA, frequently outperforming neural networks on it β
which is worth knowing, because it contradicts the
assumption that deep learning always wins.
THE ADVANTAGES OF DECISION TREES, which is why they persist:
Β· INTERPRETABLE β the path to a leaf is the explanation, and
this is the property the AI applications topic identified
as a regulatory requirement
Β· handle both numeric and categorical attributes
Β· require no feature scaling
Β· perform automatic FEATURE SELECTION, as Temperature's
absence demonstrated
Β· fast to train and to apply
Β· robust to irrelevant attributes
THE DISADVANTAGES:
Β· overfit readily without pruning
Β· HIGH VARIANCE β unstable
Β· greedy, so not optimal
Β· axis-aligned splits only, so a diagonal boundary needs
many steps to approximate
Β· biased toward many-valued attributes without gain ratio
Β· poor at learning some simple functions β parity and XOR
need an exponentially large tree
The roll-number problem is the flaw worth remembering: an attribute with a unique value per example gives maximal information gain and a completely useless tree. It splits the data into pure singletons, scores perfectly on training data, and predicts nothing. Gain ratio exists entirely to penalise that.
π Go further: the instability of single trees is not merely a caveat β it is the reason the most competitive method for tabular data is an ensemble. Gradient-boosted trees (XGBoost, LightGBM) dominate practical structured-data problems and routinely beat neural networks on them, which is worth knowing because it contradicts the assumption that deep learning wins everywhere. The explanation is that trees handle mixed types, missing values and irrelevant features natively, and boosting cancels their variance β so the inductive bias fits tabular data better than a network's smoothness prior does. Search "gradient boosted trees outperform deep learning tabular".
π‘ Exam angle: define a decision tree and state its equivalence to a rule set. Give the ID3 algorithm and note that it is greedy with no backtracking, its inductive bias being a preference for short trees. The guaranteed numerical question is entropy and information gain: know Entropy(S) = βΞ£pα΅’logβpα΅’ and Gain(S,A) = Entropy(S) β Ξ£(|Sα΅₯|/|S|)Entropy(Sα΅₯), and be able to compute all four gains on the weather dataset and build the tree. Explain why gain favours many-valued attributes and how gain ratio and the Gini index respond. Know pre- and post-pruning, the handling of continuous and missing values, and that trees are unstable so ensembles are used.
Syllabus points
ID3; entropy & information gain (numerical)
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.