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

Linear Regression OLS

线性回归 OLS
🎯Core Definition
Linear regression (OLS) assumes y=Xw+εy = Xw + \varepsilon and minimizes the residual sum of squares L(w)=∥y−Xw∥22L(w) = \Vert y - Xw\Vert_2^2. Differentiating gives ∂L∂w=2XT(Xw−y)\frac{\partial L}{\partial w} = 2X^T(Xw - y); setting it to zero yields the normal equation XTXw=XTyX^TXw = X^Ty, with closed-form solution w=(XTX)−1XTyw = (X^TX)^{-1}X^Ty when XX has full column rank — complexity about O(nd2+d3)O(nd^2 + d^3), so gradient descent (O(nd)O(nd) per step) wins in high dimensions. The 5 Gauss-Markov assumptions: (1) linearity in parameters, (2) zero conditional mean E[ε∣X]=0E[\varepsilon \mid X] = 0 (exogeneity), (3) homoscedasticity Var(ε)=σ2IVar(\varepsilon) = \sigma^2 I, (4) independent errors, (5) no perfect multicollinearity (rank(X)=drank(X) = d); normally distributed errors additionally validate small-sample t/F inference.
💡Use Cases
baseline for regression tasks; interview staples include whiteboard-deriving the normal equation, discussing what to do when XTXX^TX is singular (pseudo-inverse, ridge with λI\lambda I, dropping collinear features), and comparing OLS vs gradient descent complexity.
⚡Key Problems Solved
L(w)L(w) is convex quadratic (Hessian =2XTX⪰0= 2X^TX \succeq 0), so the normal equation reaches the unique global optimum in one shot without tuning a learning rate; unlike non-parametric kkNN, OLS yields interpretable coefficients (wjw_j = marginal effect of xjx_j holding others fixed). When assumptions break (collinearity → ill-conditioned XTXX^TX; heteroscedasticity → wrong standard errors), switch to ridge or weighted least squares.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Linear Regression OLS.
Use Cases
In production engineering, what are the primary use cases for Linear Regression OLS and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Whiteboard the normal equation: expand L(w)=∥y−Xw∥2L(w) = \Vert y - Xw\Vert^2, take the gradient, set it to 0, and arrive at w=(XTX)−1XTyw = (X^TX)^{-1}X^Ty; what condition makes XTXX^TX invertible?
2
What are the 5 OLS assumptions? What happens to unbiasedness, efficiency and consistency when each is violated?
3
What if XTXX^TX is singular or ill-conditioned? Compare pseudo-inverse, ridge w=(XTX+λI)−1XTyw = (X^TX + \lambda I)^{-1}X^Ty and dropping collinear features.
4
State the Gauss-Markov theorem: under the 5 assumptions OLS is BLUE — why is normality not among them?
5
Derive the normal equation's complexity (building XTXX^TX is O(nd2)O(nd^2), inversion O(d3)O(d^3)) and explain why high-dimensional sparse settings prefer gradient descent.
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Linear Regression OLS"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
Next Card →VIF Multicollinearity

🔗 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/linear-regression
中文速览与面试要点

线性回归 OLS (Linear Regression OLS)

定义: 线性回归 (OLS, 普通最小二乘) 假设 y = Xw + , 目标是让预测超平面离样本最近——最小化残差平方和 L(w) = y - Xw _2^2。展开并对 w 求导: L w = 2X^T(Xw - y), 令梯度为 0 得正规方程 X^TXw = X^Ty, 当 X 满列秩 (X^TX 可逆) 时闭式解 w = (X^TX)^-1X^Ty, 复杂度约 O(nd^2 + d^3) (构造 X^TX + 求逆), 高维下改用梯度下降 (每轮 O(nd))。5 大假设 (Gauss-Markov): ① 线性性 (真实关系对参数线性) ② 零条件均值 E[ X] = 0 (外生性) ③ 同方差 Var( ) = ^2 I ④ 误差相互独立 ⑤ 无完全多重共线性 (rank(X) = d); 再做小样本推断还需误差正态分布。 使用场景: 回归任务的基线模型; 面试高频: 白板推导正规方程、讨论 X^TX 不可逆怎么办 (伪逆 / 岭回归加 I / 剔除共线特征)、OLS 与梯度下降复杂度对比。 解决的问题: L(w) 是凸二次函数 (Hessian = 2X^TX 0), 正规方程一步求出全局最优, 无需调学习率; 相比 kNN 等非参数方法, OLS 给出可解释系数 (w_j 即控制其它变量后 x_j 的边际效应)。但 5 大假设被违反时 (共线 → X^TX 病态、异方差 → 标准误失真), 需转向岭回归或加权最小二乘。

核心要点

  • 白板推导正规方程: 展开 L(w) = y - Xw ^2 求梯度、令为 0, 写出 w = (X^TX)^-1X^Ty; X^TX 可逆需要什么条件?
  • 线性回归 5 大假设分别是什么? 每一条被违反时估计量的无偏性/有效性/一致性会怎样?
  • X^TX 奇异或病态怎么办? 比较伪逆、岭回归 w = (X^TX + I)^-1X^Ty 与剔除共线特征三种方案。
  • 陈述 Gauss-Markov 定理: 5 大假设下 OLS 是 BLUE (最优线性无偏估计), 为什么正态性假设不在其中?
  • 推导正规方程的时间/空间复杂度 (构造 X^TX 为 O(nd^2), 求逆为 O(d^3)), 说明高维稀疏场景为什么选梯度下降。