Decision Trees
How decision trees partition the feature space, greedy top-down induction, impurity measures (entropy, Gini, misclassification error), information gain and gain ratio worked step by step, splitting numeric attributes, regression trees with variance reduction, stopping rules and pruning, overfitting, and ensembles built from trees (bagging, random forests, boosting).
How a decision tree predicts
A decision tree asks a sequence of simple questions about one feature at a time ("Outlook = sunny?", "age < 30?"). Internal nodes test a feature, branches are outcomes, and leaves hold a prediction (a class, or a number for regression). The tree partitions the feature space into axis-aligned rectangles.
Growing a tree: greedy top-down induction
- Start with all training data at the root.
- For every feature (and threshold), measure how much a split would reduce impurity.
- Split on the best one; recurse on each child.
- Stop when a node is pure, too small, too deep, or no split helps.
This greedy recursive partitioning (ID3, C4.5, CART) is fast but not globally optimal (finding the optimal tree is NP-hard).
Impurity measures
For a node with class proportions :
| Measure | Formula | Two classes, maximum |
|---|---|---|
| Entropy | 1 at | |
| Gini impurity | 0.5 at | |
| Misclassification error | 0.5 at |
Entropy and Gini are smooth and usually pick similar splits; misclassification error is too insensitive for growing trees.
Information gain
Gain ratio (C4.5) divides by the split information to avoid favouring many-valued attributes; Gini gain (CART) uses in place of and makes binary splits.
Numeric features
Sort the values; candidate thresholds are midpoints between consecutive distinct values (only class-changing boundaries matter for entropy). Evaluate each threshold like a binary attribute.
Regression trees
Leaves predict the mean target of their examples; splits minimise the total squared error (variance reduction):
Overfitting and pruning
A tree grown until every leaf is pure has zero training error and high variance. Controls:
- Pre-pruning (early stopping): max depth, minimum samples per leaf/split, minimum impurity decrease.
- Post-pruning: grow fully, then remove subtrees that do not improve validation performance — reduced-error pruning, or cost-complexity pruning (minimise , with chosen by cross-validation).
Strengths and weaknesses
| Strengths | Weaknesses |
|---|---|
| interpretable rules; easy to visualise | unstable: small data changes can change the tree a lot (high variance) |
| no feature scaling needed; handles mixed types | axis-aligned splits approximate diagonal boundaries poorly |
| captures interactions and non-linearity | greedy; can overfit without pruning |
| fast prediction () | piecewise-constant regression |
Ensembles of trees
| Method | Idea | Mainly reduces |
|---|---|---|
| Bagging | train trees on bootstrap samples; average/vote | variance |
| Random forest | bagging + a random subset of features at each split (decorrelates trees); out-of-bag error estimate for free | variance |
| Boosting (AdaBoost, gradient boosting, XGBoost) | add shallow trees sequentially, each fitting the current errors/residuals | bias (and variance) |
Quick revision
Practice questions
GATE-style questions: 4 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
A node contains 9 positive and 5 negative examples. Its entropy (base 2) is ______ (round to two decimals).
A node has 6 examples of class A and 2 of class B. Its Gini impurity is ______.
A node with 9 positive and 5 negative examples (entropy 0.940) is split on Outlook into Sunny (2+, 3−), Overcast (4+, 0−) and Rain (3+, 2−). The information gain of this split is ______ (round to two decimals).
For a binary classification node, entropy is maximised when the fraction of positive examples is
Which statements about decision trees are correct?
One or more options are correct.
Information gain is biased towards attributes with many distinct values (such as a customer ID). C4.5 corrects this by using
A numeric feature takes 6 distinct values in a node's training examples. The number of candidate binary split thresholds (midpoints between consecutive sorted distinct values) is ______.
In a regression tree, a leaf predicts
The maximum number of leaves in a binary decision tree of depth 3 (the root is at depth 0) is ______.
A random forest improves on a single deep decision tree mainly by