← Back to Classic ML Mind Map
中文·English
📊 Classic MLID: tree-pruning

Tree Pruning

决策树剪枝
🎯Core Definition
Pruning is structural regularization for decision trees, trading off training fit against model complexity. Cost-complexity pruning minimizes Rα(T)=R(T)+α∣T∣R_\alpha(T) = R(T) + \alpha |T|, where R(T)R(T) is the empirical risk — for classification the weighted misclassification rate over leaves R(T)=∑t∈leaves(T)∣Dt∣∣D∣⋅err(t)R(T) = \sum_{t \in \text{leaves}(T)} \frac{|D_t|}{|D|} \cdot \text{err}(t), for regression the weighted MSE — ∣T∣|T| is the number of leaves, and α≥0\alpha \geq 0 penalizes each leaf. Pre-pruning stops growth before a split if validation error does not drop (or samples fall below a threshold); post-pruning (CART) grows the full tree first, then bottom-up considers each internal node tt: replacing subtree TtT_t by a leaf tt changes the cost from R(Tt)+α∣Tt∣R(T_t) + \alpha |T_t| to R(t)+αR(t) + \alpha, and equality yields the critical α=R(t)−R(Tt)∣Tt∣−1\alpha = \frac{R(t) - R(T_t)}{|T_t| - 1} — prune whenever α\alpha exceeds this value. CART starts from α=0\alpha = 0 and repeatedly prunes the node with the smallest critical α\alpha (weakest-link pruning), producing a nested sequence T0⊃T1⊃⋯⊃TkT_0 \supset T_1 \supset \cdots \supset T_k, then selects the tree minimizing validation error, i.e. picks α∗\alpha^*. C4.5 uses pessimistic pruning with a continuity-corrected error Rpe(t)=err(t)+∣Tt∣2∣Dt∣R_{pe}(t) = \frac{\text{err}(t) + \frac{|T_t|}{2}}{|D_t|}.
💡Use Cases
classic questions about tree overfitting and how max_depth / min_samples_leaf relate to α\alpha; it is also the bridge to XGBoost's γ\gamma (minimum split gain, equivalent to post-pruning) and to why random forests skip pruning and rely on randomization.
⚡Key Problems Solved
a fully grown tree can drive training error to zero but has huge variance — pre-pruning is cheap (stop as you grow) but shortsighted (a split with no immediate gain may unlock big gains deeper, so early stopping underfits); post-pruning is global and generalizes better but costs more. Cost-complexity pruning reduces tree selection to a one-dimensional problem: the exponential set of subtrees collapses to a nested chain of ∣T∣+1|T| + 1 candidates, and one cross-validation pass fixes α∗\alpha^* — the canonical answer to the bias-variance tradeoff in trees.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Tree Pruning.
Use Cases
In production engineering, what are the primary use cases for Tree Pruning and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Whiteboard cost-complexity Rα(T)=R(T)+α∣T∣R_\alpha(T) = R(T) + \alpha |T|: meaning of each symbol; how does the optimal subtree shrink as α\alpha grows?
2
Derive the pruning criterion: why prune node tt to a leaf iff R(t)−R(Tt)∣Tt∣−1≤α\frac{R(t) - R(T_t)}{|T_t| - 1} \leq \alpha?
3
Pre-pruning vs post-pruning: time cost, over/underfitting risk, and generalization comparison
4
CART weakest-link pruning: how is the nested subtree sequence generated? How is α∗\alpha^* chosen by cross-validation?
5
How pruning affects bias-variance; relationship with XGBoost's γ\gamma, max_depth, and min_samples_leaf
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Tree Pruning"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice ➔
← Previous CardDecision Tree SplittingNext Card →Bagging & Random Forest

🔗 More Classic ML Knowledge Cards

AdaBoost DerivationBaum-Welch (HMM EM)GBDT Negative GradientConfusion Matrix