2.3.5Tree-Based & Instance Methods

Overfitting in decision trees

1,885 words9 min readdifficulty · medium6 backlinks

WHY do trees overfit so easily?

The danger is structural:

  • No built-in stopping — nothing stops a tree from growing until purity.
  • Every split reduces training loss (or leaves it unchanged), so pure greed always says "split more."
  • Variance explodes: a tiny change in the training data can flip a split near the top and rewrite the whole tree below it.

WHAT does overfitting look like?

Figure — Overfitting in decision trees

The classic signature: as tree depth increases, training error → 0 monotonically, but validation error follows a U-shape — it drops, hits a sweet spot, then climbs.


HOW do we detect and fix it?

Detection

  • Compare train vs validation accuracy. A large gap = overfitting.
  • Plot the U-shaped validation curve vs depth / number of leaves.

Fix 1 — Pre-pruning (early stopping)

Stop growing before the tree gets too complex. WHY it works: it caps capacity, so the tree can't isolate noise. Common knobs:

  • max_depth — hard depth limit.
  • min_samples_split — don't split a node with too few samples.
  • min_samples_leaf — every leaf must hold ≥ k points (so leaves are statistically meaningful).
  • min_impurity_decrease — only split if it helps "enough."

Fix 2 — Post-pruning (cost-complexity / weakest-link pruning)

Grow the full tree first, then prune branches back. This avoids the myopia problem because you can see the whole subtree before deciding.

Fix 3 — Ensembling (bag the variance away)

Since overfitting is a variance problem, average many trees: Random Forests train many deep trees on bootstrap samples + random feature subsets and average them. Averaging nn roughly-independent trees cuts variance by ~1/n1/n without raising bias much.


Worked Examples


Recall Feynman: explain to a 12-year-old

Imagine you study for a test by memorizing the exact answers to last year's paper — including the printing typos. You'll ace that paper but flunk this year's, because the questions changed. A decision tree that grows too deep does the same: it memorizes every wobble in the practice data. Pruning is like telling yourself "learn the idea, don't memorize the typos" — you cut away the over-specific stuff so you do well on new questions.


Active-recall flashcards

Why do unpruned decision trees overfit?
They have very high capacity and greedily split until leaves are pure, isolating individual noisy points — low bias, very high variance.
In the bias–variance decomposition, overfitting corresponds to a large ___ term.
Variance.
What is the visual signature of overfitting vs tree depth?
Training error keeps falling to 0 while validation error is U-shaped (drops then rises).
Define cost-complexity of a tree.
Rα(T)=R(T)+αT~R_\alpha(T)=R(T)+\alpha|\tilde T|: training error plus a penalty α\alpha per leaf.
Give the effective-α\alpha (weakest-link) formula for node tt.
α=R(t)R(Tt)T~t1\alpha = \dfrac{R(t)-R(T_t)}{|\tilde T_t|-1}.
Why is the denominator T~t1|\tilde T_t|-1?
Pruning removes T~t|\tilde T_t| leaves and adds 1 back, a net loss of T~t1|\tilde T_t|-1 leaves; α\alpha = error rise per leaf removed.
Why can pre-pruning underfit (steel-man)?
It's greedy/myopic: a split may look useless now but enable great splits below (e.g. XOR); stopping early kills useful structure.
Why does post-pruning avoid that problem?
It grows the full tree first, so it can judge a whole subtree's value before deciding to cut.
Name three ways to combat overfitting in trees.
Pre-pruning (max_depth, min_samples_leaf...), post-pruning (cost-complexity), and ensembling (random forests).
Why do random forests reduce overfitting?
Overfitting is a variance problem; averaging many de-correlated deep trees drives variance down ~1/n1/n with little bias increase.
As α\alpha increases in cost-complexity pruning, the tree gets ___.
Smaller (more branches pruned) — more bias, less variance.

Connections

  • Decision Trees — the base model being regularized here.
  • Bias-Variance Tradeoff — overfitting = high-variance regime.
  • Random Forests — variance reduction by bagging trees.
  • Cross-Validation — how we choose depth / α\alpha.
  • Gini Impurity and Entropy — the split criterion R(T)R(T) measures.
  • Regularization — the αT~\alpha|\tilde T| penalty is a regularizer.

Concept Map

splits until

memorizes

causes

high capacity means

dominates in

explains why

signature

detected by

fixed by

fixed by

myopic risk

grows full tree avoids

read via

Decision tree greedy splitter

Pure leaves

Training noise

Overfitting

High variance low bias

Bias-variance decomposition

U-shaped validation curve

Train vs validation gap

Pre-pruning early stopping

Post-pruning cost-complexity

Underfitting XOR problem

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, decision tree ka kaam hai baar-baar data ko split karna jab tak har leaf "pure" na ho jaye. Problem yeh hai ki agar hum tree ko bina roke badhne dein, toh woh training data ke chhote-chhote noise ko bhi ekdum yaad kar leta hai — jaise koi student purane paper ke exact answers, typos ke saath, ratta maar le. Isko hi overfitting kehte hain: training pe 100% accuracy, lekin naye (test) data pe performance gir jaati hai.

Bias-variance ki language mein, deep tree ka bias kam hota hai par variance bahut zyada. Iska signature simple hai: depth badhao toh training error 0 tak girta jaata hai, lekin validation error pehle girta hai phir wapas U-shape mein upar aa jaata hai. Us U ka lowest point hi tumhara best depth hai.

Fix teen tarah ke hain — yaad rakho "PPE". Pre-pruning: tree ko pehle hi rok do (max_depth, min_samples_leaf jaise knobs). Lekin yeh thoda greedy/myopic hai — XOR jaise cases mein ek split abhi bekaar dikhta hai par neeche do accha split de sakta tha, toh early stop karne se underfit ho jaata hai. Post-pruning (cost-complexity): pehle poora tree grow karo, phir formula α=R(t)R(Tt)T~t1\alpha=\frac{R(t)-R(T_t)}{|\tilde T_t|-1} se weakest link kaat-kaat ke chhota karo, aur best α\alpha cross-validation se choose karo. Ensemble (Random Forest): bahut saare deep trees ka average lo — variance 1/n1/n ke ratio se gir jaata hai. Bas yaad rakho: overfit tree matlab "perfect on paper, poor in practice."

Go deeper — visual, from zero

Test yourself — Tree-Based & Instance Methods

Connections