← Back to Classic ML Mind Map
📊 Classic MLID: logistic-regression

Logistic Regression

逻辑回归 Log-Odds
🎯Core Definition
logistic regression models the log-odds as a linear function ln⁡p1−p=wTx+b\ln\frac{p}{1-p} = w^Tx + b, which inverts to the Sigmoid p=11+e−(wTx+b)∈[0,1]p = \frac{1}{1 + e^{-(w^Tx + b)}} \in [0,1]. Parameters come from MLE: the per-sample log-likelihood yln⁡p+(1−y)ln⁡(1−p)y\ln p + (1-y)\ln(1-p) negated is cross-entropy L=−∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)]L = -\sum_i [y_i \ln p_i + (1-y_i)\ln(1-p_i)]. Differentiating w.r.t. z=wTx+bz = w^Tx + b using p′=p(1−p)p' = p(1-p) gives ∂L∂z=p−y\frac{\partial L}{\partial z} = p - y, hence ∂L∂w=(p−y)x\frac{\partial L}{\partial w} = (p - y)x; there is no closed form, so optimize by gradient descent / Newton (convex, unique global optimum).
💡Use Cases
the binary-classification baseline (CTR, credit risk, diagnosis); whiteboard staples include deriving Sigmoid from log-odds, deriving ∂L∂z=p−y\frac{\partial L}{\partial z} = p - y, and contrasting LR with SVM / naive Bayes.
⚡Key Problems Solved
fitting raw linear regression to probabilities yields illegal values outside [0,1][0,1] and is outlier-sensitive; LR guarantees valid probabilities, and the CE gradient p−yp - y decays only linearly as z→±∞z \to \pm\infty (never saturates), whereas squared loss 12(p−y)2\frac{1}{2}(p-y)^2 gives vanishing gradients near p→yp \to y — slow to train; adding λ2∥w∥2\frac{\lambda}{2}\Vert w\Vert^2 yields regularized LR for high-dimensional collinearity.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Logistic Regression.
Use Cases
In production engineering, what are the primary use cases for Logistic Regression and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Whiteboard: invert ln⁡p1−p=wTx+b\ln\frac{p}{1-p} = w^Tx + b into p=11+e−wTxp = \frac{1}{1+e^{-w^Tx}}, then derive ∂L∂z=p−y\frac{\partial L}{\partial z} = p - y via p′=p(1−p)p' = p(1-p) and the chain rule.
2
Why does LR use cross-entropy instead of squared loss? Explain the gradient saturation of squared loss as p→yp \to y.
3
Show MLE ≡ cross-entropy: derive the negative log-likelihood L=−∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)]L = -\sum_i [y_i \ln p_i + (1-y_i)\ln(1-p_i)].
4
Compare LR vs SVM: hinge vs log loss, probabilistic output, support-vector dependence, and outlier robustness.
5
Why can't LR do multiclass directly? Contrast OvR vs Softmax extensions, and how class imbalance shifts the decision threshold.
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Logistic Regression"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardVIF MulticollinearityNext Card →Multiclass Strategies: OvR/OvO/Softmax

🔗 More Classic ML Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/ML/card/logistic-regression
中文速览与面试要点

逻辑回归 Log-Odds (Logistic Regression)

定义: 逻辑回归把对数几率 (Log-Odds) 建模为输入的线性函数 p1-p = w^Tx + b, 反解得 Sigmoid p = 11 + e^-(w^Tx + b) [0,1]。参数由极大似然估计 (MLE) 求解: 单样本对数似然 y p + (1-y) (1-p), 取负即交叉熵 L = - _i [y_i p_i + (1-y_i) (1-p_i)]。对 z = w^Tx + b 求导: Sigmoid 导数 p' = p(1-p), 代入链式法则得 L z = p - y, 从而 L w = (p - y)x; 目标无闭式解, 用梯度下降/牛顿法迭代 (凸优化, 全局最优)。 使用场景: 二分类基线 (CTR、风控、医疗诊断); 面试高频白板题: 从 Log-Odds 推出 Sigmoid、推导 L z = p - y、对比 LR 与 SVM/朴素贝叶斯。 解决的问题: 线性回归直接拟合概率会输出 1 的非法值且对异常值敏感; LR 用 Sigmoid 保证概率合法, 且交叉熵梯度 p-y 在 z 时只线性衰减 (永不消失), 而平方损失 12(p-y)^2 在 p y 或 z 很大时梯度 0 (饱和), 收敛极慢; 加 2 w ^2 即带正则 LR, 缓解高维共线性。

核心要点

  • 白板推导: 从 p1-p = w^Tx + b 反推 p = 11+e^-w^Tx, 再用 p' = p(1-p) 与链式法则推导 L z = p - y。
  • 为什么 LR 用交叉熵而不是平方损失? 从梯度角度说明平方损失在 p y 时的饱和问题。
  • 写出 MLE 与交叉熵的等价性: 负对数似然 L = - _i [y_i p_i + (1-y_i) (1-p_i)] 的推导。
  • LR 与 SVM 对比: hinge loss vs 对数损失的差异、是否输出概率、是否依赖支持向量、对异常值的鲁棒性。
  • 逻辑回归为什么不能直接做多分类? 对比 OvR/Softmax 两种扩展, 以及类别不平衡对决策阈值的影响。