skip to content

Pruning and Stopping

Left alone a tree grows until every leaf is pure, so depth caps and minimum-samples rules halt growth early while cost-complexity pruning cuts it back after. Interviewers probe overfitting here.

on this pageshow

questions

4

Which growth-stopping limits keep a decision tree from splitting until every leaf is pure?

level: juniorimportance: must knowfreq 74%

answer

  1. growth needs to be told when to stop
  2. cap levels, count rows
  3. a floor under each child leaf
  4. gain must clear a threshold
  5. all checked before the split is made

basics

~20 s

Four pre-pruning limits: a maximum tree depth, a minimum node size to split, a minimum number of samples per resulting leaf, and a minimum impurity decrease per split. Any split breaking one of them is refused.

solid answer

~40 s

A tree's growth is greedy and has no natural stopping point, so you impose limits before growth. **Maximum depth** caps how many splits deep any path can go. **Minimum samples to split** refuses to split a node that holds too few rows. **Minimum samples per leaf** refuses any split that would leave a child below a floor, so it constrains the result rather than the parent. **Minimum impurity decrease** refuses a split whose weighted impurity gain is below a threshold, so a split that moves Gini by 0.0004 against a 0.001 threshold never happens. Some implementations also cap the total number of leaves. All of these are checked while the tree is being built, which is why they are called pre-pruning; they also make training cheaper, since the recursion stops earlier.

go deeper

for a junior

Be able to name the limits and say what each one refuses: a depth cap, a minimum node size to split, a minimum leaf size, and a minimum impurity gain. Also be ready to say why an unlimited tree reaches 100% training accuracy.

for a middle

Explain the mechanics: which rule inspects the parent and which inspects the children, that the impurity decrease is weighted by the share of rows reaching the node, and that these checks happen during construction rather than afterwards.

for a senior

Show judgment about which limit to actually tune on a given dataset, why several tight limits at once obscure which one binds, and how you verify the choice on held-out data instead of the training score.

for a principal

Own the tradeoff between a tree small enough for a domain expert to read and audit, and one accurate enough to deploy — and the fact that the limits you standardise on become the de facto complexity policy for every model built from that template.

## Why a tree needs to be stopped at all A CART tree is grown greedily. At each node the algorithm scans candidate feature-and-threshold cuts and keeps the one that most reduces impurity in the two children. Nothing in that loop knows when to quit: as long as a node still holds rows with different labels, some cut will reduce impurity, so the recursion continues until every leaf is pure or holds rows that are identical in the features. Take a 30-day hospital readmission model grown that way. The tree ends with roughly one patient per leaf and reports 100% training accuracy. That number is a tautology, not evidence: each training patient is being looked up in a leaf that was carved around that patient. A new patient falls into a leaf shaped by one other person's idiosyncrasies, and the prediction is whatever that single person's outcome happened to be. So growth has to be told when to stop. The controls that do it are applied *during* construction, which is what distinguishes them from pruning a finished tree. ## The four limits **Maximum depth.** A hard cap on how many splits separate the root from any leaf. A depth-4 tree has at most 16 leaves and at most 4 conditions on any decision path. It is the bluntest control: it applies the same budget to every branch, whether that branch carries 60% of the training rows or 0.5% of them. **Minimum samples to split an internal node.** A node holding fewer rows than the threshold is turned into a leaf without any cut being considered. This looks at the *parent*. **Minimum samples per leaf.** A candidate split is rejected if either child would end up below the floor. This looks at the *children*, and it is the stronger of the two sample rules: with a floor of 50, no leaf anywhere in the tree can hold fewer than 50 training rows, so every leaf prediction rests on at least that many observations. It adapts to the data — dense regions can still go deep, sparse branches stop early — which is why it is usually a better knob than depth alone. **Minimum impurity decrease.** A split is accepted only if the impurity it buys clears a threshold. The quantity compared is normally *weighted* by how much of the training set reaches the node: ``` decrease = (N_t / N) * ( impurity(t) - (N_L/N_t)*impurity(L) - (N_R/N_t)*impurity(R) ) ``` where `N` is the training-set size, `N_t` the rows at node `t`, and `N_L`, `N_R` the rows going left and right. The weighting matters: a deep node holding 1% of the data must produce a hundred times the local impurity drop of a root-level split to clear the same threshold. Set the threshold at 0.001 and a candidate split that moves Gini by 0.0004 is refused outright — the node stays a leaf unless some other candidate does better. Many implementations also expose a cap on the total number of leaves, which grows the tree best-first and stops at the budget rather than capping depth uniformly. ## How they interact These limits are not independent. A leaf-size floor of 50 on a 900-row dataset already implies at most 18 leaves, which implies an effective depth of about 4 even with no depth cap. Setting several tight limits at once makes it hard to say which one is actually binding, so when tuning, it is common to move one of them — usually the leaf-size floor or the depth cap — and leave the others loose. Also note what these limits do *not* do. They are checked one split at a time with no lookahead, so a split whose value only appears one level lower is simply never taken. And a limit that is too tight underfits: a depth cap of 2 on a problem with five interacting features cannot express the answer regardless of how much data you have. ## What to say about defaults Out of the box, most tree implementations set none of these meaningfully: depth is unlimited, the split threshold is 2 rows, the leaf floor is 1 row, and the impurity threshold is 0. In other words, the default behaviour *is* growth to purity. That is a deliberate choice, because the same code is reused inside averaged ensembles where deep individual trees are acceptable — but for a single tree that you intend to read or deploy, leaving the defaults is the mistake. Pick a leaf-size floor that reflects how many observations you need behind each prediction, then check the choice on held-out data rather than on the training score.

  • Why is a leaf-size floor usually a better control than a depth cap?
    A depth cap spends the same budget on every branch regardless of how much data flows down it, so a branch carrying 60% of the rows and one carrying 0.5% both stop at the same level. A leaf-size floor adapts: dense regions keep splitting while sparse branches stop as soon as a child would be too small, so the constraint tracks the evidence available.
  • How does the number of rows at a node affect whether it clears a minimum-impurity-decrease threshold?
    The decrease is normally weighted by the fraction of the training set reaching the node. A node holding 1% of the data contributes only 1% of its local impurity drop to the compared quantity, so deep, small nodes have to show a much larger local gain than root-level splits to clear the same threshold. That makes one global threshold behave like an increasingly strict rule as the tree deepens.
  • Do these limits make training faster or slower?
    Faster. Each refused split removes an entire subtree's worth of candidate-split scanning, so the recursion terminates earlier and less of the data is re-sorted at depth. That is a real advantage over pruning a finished tree, which pays the full cost of growing to purity first and only then discards work.

Like budget rules on a contractor: a limit on floors, a minimum crew per floor, and a rule that no change order is approved unless it improves the building measurably.

saying these in an interview costs you the question

  • Says a tree stops on its own when accuracy is good
  • Confuses minimum samples to split with minimum samples per leaf
  • Treats 100% training accuracy as evidence the tree works
  • Thinks default settings already limit tree growth
  • Believes the impurity threshold ignores how many rows reach the node

context

open as a page

How does cost-complexity pruning use alpha to shrink a fully grown decision tree?

level: middleimportance: must knowfreq 55%

basics

~20 s

Cost-complexity pruning scores a tree as training error plus alpha times its leaf count, then collapses the subtree with the smallest error cost per leaf removed. Larger alpha yields a smaller tree, and alpha is chosen by cross-validation.

open as a page

How do you set a decision tree's minimum leaf size on a 900-row cohort with only 36 positive cases?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Size leaves by expected positive cases, not total rows: at a 4% rate, 50-row leaves hold about two positives, so their probabilities are noise. Divide the events you need behind a prediction by the prevalence.

open as a page

Why can a decision tree's pre-pruning rules reject a split that post-pruning would keep?

level: middleimportance: nice to knowfreq 30%

basics

~10 s

Pre-pruning judges each split on its immediate gain with no lookahead, so a near-worthless split that unlocks a strong one a level below is refused. Post-pruning grows first and judges the pair together.

open as a page