M2-023M2: Classical Machine LearningDecision TreesEasy
Mastery:

Decision Trees: 决策树如何防止过拟合?列出主要手段。

📐 Mathematical Definition
cost complexity: Rα(T)=R(T)+α∣T∣\text{cost complexity}:\ R_\alpha(T)=R(T)+\alpha|T|
⚡ Executive Summary
Core Concept: 预剪枝(最大深度/最小样本/最小增益)+ 后剪枝(代价复杂度)+ 集成。

📌 Key Takeaways

  • •
    预剪枝快但可能欠拟合
  • •
    后剪枝通常效果更好
  • •
    实际多直接用随机森林/GBDT

📐 Mathematical Derivations

两类剪枝策略:① <strong>预剪枝(pre-pruning)</strong>——在生长过程中提前停止:限制最大深度(max_depth)、最小叶样本数(min_samples_leaf)、最小分裂样本数(min_samples_split)、最小不纯度下降(min_impurity_decrease)、最大叶节点数。优点是快,缺点是<strong>贪心停止可能错过后续更有用的分裂</strong>(因为当前分裂看起来增益小但为后续铺路),导致欠拟合。② <strong>后剪枝(post-pruning)</strong>——先长成完整树再自底向上剪:<strong>代价复杂度剪枝</strong>(CCP)最小化 R_α(T)=R(T)+α|T|,其中 R(T) 是训练误差、|T| 是叶节点数、α 是惩罚系数;α=0 不剪、α→∞ 剪成单节点,通过 CV 选 α。其他方法包括<strong>错误率降低剪枝</strong>(REP)、<strong>悲观剪枝</strong>(PEP,C4.5 用,无需额外验证集)。

🏭 Production Trade-offs

实践要点:① <strong>后剪枝通常优于预剪枝</strong>——因为它基于完整树的全局信息做决策,而非贪心提前停止;但计算成本更高。② <strong>单棵树的根本问题</strong>——即使剪枝,单棵树仍<strong>方差大</strong>(训练数据微小扰动会导致结构大变),这是 Bagging/随机森林的直接动机。③ <strong>实践中的选择</strong>——现代实践中很少直接用单棵树:若需要可解释性,用<strong>浅树</strong>(深度 3–5)+ 预剪枝;若追求性能,用随机森林(深树 + 平均降方差)或 GBDT(浅树 + 串行降偏差)。④ <strong>sklearn 的默认</strong>——<code>DecisionTreeClassifier</code> 默认不剪枝(完全生长),需手动设置;<code>ccp_alpha</code> 参数控制代价复杂度剪枝强度,可用 <code>cost_complexity_pruning_path</code> 得到候选 α 序列。
⚠️ Common Interview Pitfalls
  • ✕
    认为预剪枝总是更好(可能欠拟合)
  • ✕
    让单棵树完全生长而不剪枝(严重过拟合)
🎯 Interviewer Follow-ups
  • ?
    预剪枝与后剪枝的取舍?
  • ?
    为什么单棵树方差大?
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM2-022: Decision Trees: 解释决策树的分裂准则(信息增益 / 基尼不纯度)。📋Back to BankNext →M2-024: Decision Trees: 决策树为什么不需要特征缩放?它的归纳偏置是什么。