M2-119M2: Classical Machine LearningEvaluation Metrics & Hyperparameter TuningHard
⚡Flashcard Drill➔Mastery:
Automated Hyperparameter Optimization Tools and Industrial Best-Practice Workflows
📐 Mathematical Definition
⚡ One-Sentence Core Answer
Tools like Optuna and Ray Tune implement TPE, Hyperband, and ASHA to optimize hyperparameters through coarse screening, fine tuning, and early trial pruning.
📌 Key Takeaways
- •TPE (Tree-structured Parzen Estimator): models densities for good vs bad configurations, optimizing expected improvement
- •ASHA (Asynchronous Successive Halving): aggressively terminates underperforming trials asynchronously across distributed workers
- •Workflow: coarse random/ASHA search fine Bayesian tuning multi-seed validation
📐 Mathematical Derivations
TPE Algorithm Formulation (Bergstra et al.): Instead of modeling directly as in Gaussian Processes, TPE uses Bayes rule by splitting configurations based on quantile :
, where is the -quantile of observed scores.
The Expected Improvement (EI) optimization simplifies to maximizing the density ratio: . TPE samples candidate hyperparameter points from that maximize the likelihood ratio .
, where is the -quantile of observed scores.
The Expected Improvement (EI) optimization simplifies to maximizing the density ratio: . TPE samples candidate hyperparameter points from that maximize the likelihood ratio .
🏭 Production Trade-offs
Industrial framework selection: ① Optuna: Lightweight, pythonic, dynamic search spaces, supports SQLite/PostgreSQL storage; ideal for single-node multi-GPU pipelines. ② Ray Tune: Built on Ray, seamless cluster scaling, supports ASHA and Population Based Training (PBT); ideal for distributed deep learning.
⚠️ Common Interview Pitfalls
- ✕Searching continuous parameters like learning rate on a uniform linear scale instead of a logarithmic scale (
log=True) - ✕Tuning hyperparameters on the test dataset rather than an independent cross-validation split, introducing severe selection leakage
🎯 Interviewer Follow-up Inquiries
- ?How does Asynchronous Successive Halving (ASHA) eliminate synchronization bottlenecks in distributed hyperparameter search?
- ?What is Population Based Training (PBT), and how does it dynamically adapt hyperparameters during model training?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
📚
Associated Knowledge Base Guides & Mindmaps
Explore the comprehensive technical article, exam cards, and global architecture tree.
中文速览与面试要点
解释超参调优的自动化工具与实践流程
Optuna/Ray Tune 提供 TPE、Hyperband、ASHA 等算法;流程是分阶段(粗筛→精调)并按重要度排序。
核心要点
- 主流工具与算法:① Optuna (TPE + 剪枝)——用 树结构 Parzen 估计器(TPE) 建模'好配置'与'坏配置'的超参分布,按密度比采样(比随机搜索更聚焦);支持 剪枝 (对表现差的试验提前终止)与分布式并行。② Ray Tune ——支持多种搜索算法(ASHA、HyperBand、PBT)与大规模并行,适合集群环境。③ Hyperband/ASHA —— 连续减半 (successive halving):先用小预算评估大量配置,淘汰表现差的(保留 top 1/η),对幸存者加大预算,迭代直至只剩一个; ASHA 是异步版本 (无需等待全部完成,适合异构并行)。④ PBT(Population Based Training) ——在训练过程中动态调整超参(表现差的个体从好的个体继承参数并扰动),适合长训练任务。⑤ 贝叶斯优化(GP 类) ——用高斯过程建模,样本效率最高但难以并行、维度受限。 选择依据 :预算小 → 随机搜索;中等 → TPE/Hyperband;极大预算或集群 → ASHA/PBT。
- 实践流程与陷阱:① 分阶段调参 ——(a) 粗筛 :用大范围随机搜索或 Hyperband 找有希望的区域;(b) 精调 :在局部用 TPE/贝叶斯优化细搜;(c) 验证 :用独立测试集或嵌套 CV 确认。② 按重要度排序 ——先调 学习率 (最重要)、再调正则强度与模型容量、最后调次要参数;不要平均用力(见'超参重要度'题)。③ 参数空间的设定 ——学习率、正则系数等应在 对数尺度 搜索;离散参数(优化器类型、激活函数)用 类别分布 ;并设置合理边界(过宽浪费预算)。④ 剪枝策略 ——用 中位数剪枝 (若某试验在中途的表现低于已完成试验的中位数则终止)能显著节省算力(常省 50%+);但需注意 早期表现差的配置可能后期反超 (如小学习率起步慢),故剪枝应留足观察窗口。⑤ 随机种子的处理 ——小数据/小模型上方差大,同一配置多次运行的差异可能超过配置间的差异;应 多种子重复 或至少对最终候选做多种子验证。⑥ 常见陷阱 ——(a) 用测试集调参(泄漏);(b) 搜索空间包含无效组合(浪费预算);(c) 忽略参数交互(学习率与 batch size、学习率与调度需联合调);(d) 过拟合验证集(在验证集上反复调参后,验证集也失去'独立'性,应用独立测试集确认);(e) 不记录实验(无法复现与归因)——应使用实验管理工具记录所有配置与结果。
- TPE 用核密度估计建模好坏配置的分布
- ASHA 用异步连续减半加速
常见陷阱
- 在对数尺度之外搜索学习率
- 用测试集做超参搜索(泄漏)