University of Sydney · FACULTY OF MACHINE LEARNING

COMP4318 · Machine Learning and Data Mining

- one subject, every graph, every model, every mark
Machine Learning14 Chapters8-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 5 of 11 · COMP4318

Decision Trees & Ensembles

Week 5 covers decision-tree induction with entropy and information gain (and Gini as an alternative), pruning, then ensembles — bagging, boosting (AdaBoost and gradient boosting) and random forests. The information-gain calculation is a near-certain exam item, and the ensemble comparison (bagging vs boosting, naming a random forest from pseudocode) is a recurring short-answer. The homework quiz (h5) drills the entropy arithmetic.

In this chapter

What this chapter covers

  • 01Top-down recursive divide-and-conquer tree induction; a node becomes a leaf when it is pure
  • 02Entropy H(S) = −Σ pᵢ·log2(pᵢ) in bits (with log2(0) = 0); pure = 0, 50/50 = 1
  • 03Information gain Gain(S,A) = H(S) − Σ (|Sᵢ|/|S|)·H(Sᵢ); pick the attribute with the highest gain
  • 04Highly-branching-attribute bias and the gain-ratio fix; Gini index as CART's alternative purity measure
  • 05Pruning: pre- vs post-pruning (post preferred), validated on a hold-out set
  • 06Ensembles work when the base classifiers are accurate (error < 0.5 for binary) AND diverse
  • 07Bagging (bootstrap samples, ~63% appear, parallel, equal weight) vs Boosting (sequential, reweight hard cases)
  • 08AdaBoost (weighted vote by accuracy) and Gradient Boosting (each tree fits the residuals); Random Forest = bagging + a random feature subset per split
Worked example · free

Entropy and information gain of a split

Q [5 marks]. A node S has 8 examples: 4 labelled Play and 4 labelled No. Splitting on the attribute Windy gives Windy=No with 5 examples (4 Play, 1 No) and Windy=Yes with 3 examples (0 Play, 3 No). Compute the information gain of the Windy split. (5 marks)
  • +1Parent entropy: with 4 Play and 4 No, H(S) = −(4/8)log2(4/8) − (4/8)log2(4/8) = −0.5·(−1) − 0.5·(−1) = 1 bit (a 50/50 split is maximally impure).
  • +1Split on Windy: Windy=No has 5 examples (4 Play, 1 No); Windy=Yes has 3 examples (0 Play, 3 No).
  • +1Child entropies: H(Windy=No) = −(4/5)log2(4/5) − (1/5)log2(1/5) = 0.722 bits; H(Windy=Yes) = 0 (pure, all No).
  • +1Weighted child entropy H(S|Windy) = (5/8)·0.722 + (3/8)·0 = 0.451 bits.
  • +1Information gain = H(S) − H(S|Windy) = 1 − 0.451 = 0.549 bits.
H(S) = 1 bit, H(S|Windy) = 0.451 bits, so the information gain is 0.549 bits — a strong split, because the Windy=Yes branch is pure.
Sia tip — Entropy is base-2 (bits) and always carries the minus sign; a pure node has entropy 0 and a 50/50 node has entropy 1. The attribute with the highest information gain becomes the node. Watch for many-valued attributes (like an ID code) that score artificially high — that bias is exactly why gain ratio exists.
Glossary

Key terms

Entropy
H(S) = −Σ pᵢ·log2(pᵢ), the impurity of a set in bits (log2(0) taken as 0); 0 = pure, 1 = an even two-class split.
Information gain
Gain(S,A) = H(S) − Σ(|Sᵢ|/|S|)·H(Sᵢ), the drop in entropy from splitting on attribute A; trees pick the highest-gain attribute.
Gini index
CART's alternative purity measure to entropy; like entropy it is 0 for a pure node and larger for mixed nodes.
Bagging
Bootstrap aggregation: build M classifiers on M bootstrap samples (drawn with replacement) in parallel and combine by majority vote (average for regression); best for unstable learners like trees.
Boosting (AdaBoost)
Sequential ensembling that reweights the examples the previous model got wrong; AdaBoost increases misclassified weights and combines by a weighted vote based on each model's accuracy.
Random Forest
Bagging of unpruned decision trees with an added random subset of k features considered at each split; combined by majority vote and robust to overfitting.
FAQ

Decision Trees & Ensembles FAQ

Entropy or Gini — does it matter which I use?

Both measure node impurity and usually pick similar splits; entropy (with information gain) is the ID3/C4.5 default and Gini is CART's measure. In this unit the information-gain calculation with entropy is the examinable routine, so master that; know Gini exists as CART's alternative and quote it if asked.

What's the difference between bagging and boosting?

Both combine many same-type learners by voting/averaging. Bagging builds them in parallel on independent bootstrap samples with equal weight, reducing variance. Boosting builds them sequentially, each focusing on the examples the previous got wrong, and combines by a performance-weighted vote — reducing bias as well. Random forest is bagging plus a random feature subset per split.

Why does an ensemble beat a single tree?

Because independent errors cancel. If the base classifiers are individually accurate (error below 0.5 for a binary problem) and diverse (their errors are not the same), the majority vote is more likely to be right than any single member — the ensemble error drops well below the individual error. Diversity is why bagging perturbs the data and random forests perturb the features.

How is the decision-tree question usually marked in the exam?

Method by method: computing the parent entropy, the child entropies, the weighted child entropy, and the gain each earn marks, plus a mark for interpreting the result (e.g. noting a pure child or choosing the best attribute). Show the entropy formula explicitly and keep the log base 2.

Study strategy

Exam move

Make the entropy/information-gain routine second nature: parent entropy, each child's entropy, the weighted sum, then the gain — always base-2, always with the minus sign, and note pure children (entropy 0) to save time. Rehearse comparing two candidate attributes' gains and choosing the larger. On the ensemble side, be able to write the bagging-vs-boosting contrast in one line and to name a random forest from its pseudocode plus two advantages. When the arithmetic slips, ask Sia to recompute a split with fresh counts and check your logs.

Working through Decision Trees & Ensembles in COMP4318? Sia is AskSia’s AI Machine Learning tutor — ask any COMP4318 Decision Trees & Ensembles question and get a clear, step-by-step explanation grounded in how COMP4318 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 12 of your University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your COMP4318 tutor, unlimited, worked the way the exam marks it
The full 8-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$25/ month
30-day money-back · cancel in one tap · how it works
Unlock the full COMP4318 Bible + 12 University of Sydney subjects解锁完整 COMP4318 Bible + University of Sydney 12 门科目
$25/mo