M2-008M2: Classical Machine LearningLogistic Regression & GLMMedium
Mastery:
Logistic Regression & GLM: 什么是广义线性模型(GLM)?它由哪三部分组成。
📐 Mathematical Definition
⚡ Executive Summary
Core Concept: GLM = 随机成分(指数族分布)+ 系统成分(线性预测子)+ 链接函数。
📌 Key Takeaways
- •线性回归:Gaussian + identity
- •逻辑回归:Bernoulli + logit
- •Poisson 回归:Poisson + log,用于计数率
📐 Mathematical Derivations
GLM 的三个组件:① <strong>随机成分</strong>——指定 Y 的分布属于<strong>指数族</strong>(Gaussian、Bernoulli、Poisson、Gamma、Inverse Gaussian 等),指数族的统一形式为 f(y;θ)=exp[(yθ−b(θ))/a(φ)+c(y,φ)],其中 b'(θ)=E[Y]、b''(θ)=Var[Y]·a(φ),这使方差与均值通过<strong>方差函数</strong> V(μ) 关联;② <strong>系统成分</strong>——线性预测子 η=Xw;③ <strong>链接函数</strong>——单调可微的 g 使 g(μ)=η,即 μ=g⁻¹(Xw)。三个经典组合:线性回归(Gaussian + identity)、逻辑回归(Bernoulli + logit)、Poisson 回归(Poisson + log)。
🏭 Production Trade-offs
GLM 的统一性带来三个实践优势:① <strong>损失函数自动确定</strong>——由分布假设推出负对数似然,无需人工选择(如 Poisson 回归的损失是 Σ(μ−y log μ),而非 MSE);② <strong>方差随均值变化</strong>——Poisson 的方差函数 V(μ)=μ(均值越大方差越大),这自动处理了计数数据的异方差,无需加权;③ <strong>系数解释通过链接函数</strong>——log 链接下 e^{βⱼ} 是'率比'(rate ratio)。<strong>为什么 CTR 建模有时用 Poisson/Gamma</strong>:CTR 是'曝光中点击的比例',若把曝光视为'暴露量',点击数服从 Poisson(λ=曝光×CTR),用 Poisson 回归配合 offset 项 log(曝光) 可以正确处理不同曝光量下的方差差异——这比直接用二项逻辑回归在曝光量差异大时更稳。此外,过度离散的计数数据可用<strong>负二项 GLM</strong>(引入额外离散参数)或 Quasi-Poisson(只放宽方差为 φμ)。
⚠️ Common Interview Pitfalls
- ✕把 GLM 当作'任何非线性模型'(它要求指数族 + 链接函数)
- ✕对过度离散的计数数据直接用 Poisson GLM
🎯 Interviewer Follow-ups
- ?为什么 CTR 建模常用 Poisson/Gamma?
- ?log 链接如何保证预测非负?
📚
Associated Knowledge Base Guides & Mindmaps
Explore the comprehensive technical article, exam cards, and global architecture tree.