Decision Trees and Regression Trees
Context: FIT1043_MOC, FIT2086_MOC, FIT3003_MOC Β· a predictive model you can read as rules Β· splits the feature space into regions Β· the building block of a Random Forest Β· how FIT2086 grows and sizes one β Decision Tree Learning (Likelihood Splits, Pruning, CV) Β· FIT3003βs hand build by lowest SSR β Regression Tree Construction (SSR Splits)
Quick Revision
- π― Objective: classify or predict by walking a tree of feature tests β decision tree = categorical, regression tree = real value; each leaf holds a fitted model for its region.
- π¦ Core Components: recursive partitioning | leaf model (Bernoulli/mode vs Normal/mean) | split criterion (purity/info gain; FIT2086: NLL) | complexity number of leaves.
- β‘ Key Constraint: the algorithmβs choices β which feature to split on and when to stop β determine the tree; a large enough fits the training data perfectly βΉ overfits.
π How It Works
1. Two Kinds of Tree
- Decision tree β predicts a binary/multi-class categorical outcome (play tennis: yes/no).
- Regression tree β predicts a continuous real value (leaves hold numbers like 45.6).
- Structure β start at the root, follow a branch per feature test, reach a leaf = the prediction.
2. Building & Predicting
- Recursive partitioning β repeatedly divide the feature space into regions that group similar instances together.
- Decision-tree leaf β predict the most common class in that region.
- Regression-tree leaf β predict the average value in that region.
3. Split Criteria & Stopping
- Which feature to split β chosen by a purity / information-gain measure (e.g. entropy); algorithms differ β ID3, C4.5, CART.
- When to stop β further splits stop helping: minimum samples per node, maximum depth, or negligible accuracy gain.
4. The Statistical View (FIT2086)
- Same job as regression β ; only the form of differs β highly non-linear, yet still interpretable.
- Partition β the splits carve predictor space into disjoint regions ; each region is a leaf.
- Leaf model β each leaf holds a model fitted to its own data: Bernoulli for binary targets Β· Normal (own mean and variance) for regression.
- Predict β traverse from the root taking the branch your satisfies β use that leafβs model.
- Complexity β (number of leaves) β more leaves βΉ closer fit to the training data.
- Multi-class β generalises directly β the leaf model becomes a categorical distribution.
5. Strengths, Weaknesses, Instability (FIT2086)
- Strengths β highly interpretable Β· handles non-linearity Β· handles interactions (split on then on βΉ they interact) Β· mixes continuous, categorical and count predictors Β· multiclass for free Β· variable selection built in (unused predictors never split).
- Non-linearity, regression β truth : linear fit misses the curve; trees with leaves give ever finer staircases, tracing it almost exactly.
- Non-linearity, classification β tree boundary = axis-aligned step line; Logistic Regression boundary = one straight line.
- Weaknesses β good tree hard to find (search is approximate) Β· unstable β a slight data change can give a drastically different tree Β· inefficient when the truth is linear (many leaves, many parameters to approximate a line).
- Instability, same 185 patients β three trees score , , β near-equal fits, different structures β no clear winner βΉ motivates random forests.
- Instability, Studio 9 diabetes β CV-pruning the 14-leaf tree to 7 leaves moves the worst-progression leaf from BMI & BP () to BMI & BP & S6 (), while BP still predicts βΉ similar predictions, different structure β Trees, Forests and kNN in R (rpart, randomForest, kknn).
βοΈ Core Implementation
πΉ Decision tree β βplay tennis?β
Mermaid tree + rule
graph TD A[outlook?] -->|sunny| B[humidity?] A -->|overcast| C[yes] A -->|rain| D[wind?] B -->|high| E[no] B -->|normal| F[yes] D -->|strong| G[no] D -->|weak| H[yes]π‘ Common Mistake: Read the tree as OR-of-AND rules β good day = (Sunny and Normal) or Overcast or (Rain and Weak); everything else is a bad day.
πΉ Decision tree β high blood pressure (FIT2086)
Mermaid tree + leaf probabilities
graph TD A[Sex?] -->|Male| B["53 / 7 Β· p = 12%"] A -->|Female| C[Age?] C -->|"Age < 50"| D["3 / 78 Β· p = 96%"] C -->|"Age β₯ 50"| E["21 / 23 Β· p = 52%"]
- Leaf label β (no / yes) βΉ : , , .
- Female, 45 β Female β Age β Β· Male, 70 β Male leaf, β age is never tested for males. π‘ Common Mistake: Reading as the probability β it is a count pair; the leaf probability is .
βοΈ Core Decision Matrix
| Tree | Predicts | Leaf value | FIT2086 leaf model |
|---|---|---|---|
| Decision tree | category (yes/no, classes) | most common class in region | Bernoulli / categorical, |
| Regression tree | real value | average value in region | Normal, own and |
When It Flips: both trees are built the same way (recursively partition the feature space); they differ only in the leaf rule β mode for classification, mean for regression.
π§ Active Recall
How does a decision tree differ from a regression tree in what it predicts and how a leaf decides?
Answer
- Short answer: A decision tree predicts a category (leaf = most common class in the region); a regression tree predicts a real value (leaf = average of the region).
- Why: Same partitioning, different leaf β both recursively split the feature space; only the leaf aggregation changes.
What two decisions define a tree-building algorithm, and name a criterion for each.
Answer
- Short answer: (1) which feature to split on β by purity/information gain (e.g. entropy; ID3/C4.5/CART); (2) when to stop β min samples, max depth, or negligible gain.
- Why: Purity + stopping β splits that best separate classes, halted before they overfit.
Why does a tree capture interactions and non-linearity with no extra columns, when linear regression needs polynomial and product terms?
Answer
- Short answer: Each leaf fits its own model to its own region, so the prediction is piecewise-constant in (non-linear), and a split on nested under a split on makes βs effect depend on (interaction).
- Why: Partition, then fit locally β is built from regions , not from a weighted sum ; the cost is inefficiency when the truth is linear.
Three trees on the same data score , , . What weakness does this show, and what fixes it?
Answer
- Short answer: Instability β near-identical goodness of fit from structurally different trees, so the chosen tree depends on small data quirks; a random forest averages many trees to cancel it.
- Why: High variance β single trees are low-bias but high-variance; averaging randomised trees keeps the low bias and cuts the variance.