M2-093M2: Classical Machine LearningLinear RegressionMedium
⚡Flashcard Drill➔Mastery:

Interaction and Polynomial Terms in Regression: Formulations and Regularization

📐 Mathematical Definition
y=w0+w1x1+w2x2+w3x1x2+εy=w_0+w_1x_1+w_2x_2+w_3x_1x_2+\varepsilon
⚡ One-Sentence Core Answer
Incorporate non-linear effects and conditional dynamics via product terms; mitigate overfitting using the hierarchical principle, centering, and L1/L2 regularization.

📌 Key Takeaways

  • •
    Polynomial terms model non-linear curvature; interaction terms model conditional feature effects
  • •
    Hierarchical principle: never include interaction x1x2x_1 x_2 without retaining main effects x1x_1 and x2x_2
  • •
    Multicollinearity control: center features (x−xˉx - \bar{x}) before computing products to reduce collinearity with main effects

📐 Mathematical Derivations

Model Formulation: y=β0+β1x1+β2x2+β12x1x2+β11x12+ϵy = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_{12} x_1 x_2 + \beta_{11} x_1^2 + \epsilon.
- Hierarchical Principle (Well-formulated Models): An interaction term β12x1x2\beta_{12} x_1 x_2 implies that the marginal effect of x1x_1 is ∂y∂x1=β1+β12x2\frac{\partial y}{\partial x_1} = \beta_1 + \beta_{12} x_2. If main effect β1\beta_1 is omitted, the model forces the marginal effect to vanish at x2=0x_2 = 0, which is an arbitrary artifact of measurement scaling.
- Centering: Raw products x1x2x_1 x_2 are naturally collinear with x1x_1 and x2x_2. Centering transforms variables to x~i=xi−xˉi\tilde{x}_i = x_i - \bar{x}_i, making Cov(x~1,x~1x~2)≈0\text{Cov}(\tilde{x}_1, \tilde{x}_1 \tilde{x}_2) \approx 0 under symmetric distributions.

🏭 Production Trade-offs

Regularization strategy: When expanding to O(d2)O(d^2) terms, apply Lasso or ElasticNet with hierarchical constraints (e.g., HierNet or Group Lasso) to ensure sparse selection while honoring structural hierarchies.
⚠️ Common Interview Pitfalls
  • ✕
    Omitting linear main effects when including interaction terms, making model predictions scale-dependent
  • ✕
    Generating uncentered polynomial terms, inducing extreme multicollinearity and numeric instability
🎯 Interviewer Follow-up Inquiries
  • ?
    Why does shifting the origin (e.g., Celsius vs Kelvin) break a regression model that contains interaction terms without main effects?
  • ?
    How does Group Lasso enforce the hierarchical principle between main effects and interaction terms?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

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

← PreviousM2-092: Weighted Least Squares (WLS) and Handling Heteroscedasticity📋Back to BankNext →M2-094: Multinomial Logistic Regression (Softmax Regression) and Parameter Identifiability
中文速览与面试要点

解释回归中的交互项与多项式项,以及如何避免过拟合

交互项捕捉'一个特征的效应依赖另一特征';多项式项捕捉非线性;需标准化与正则化。

核心要点

  • 交互项的作用:在模型 y=w₀+w₁x₁+w₂x₂+w₃x₁x₂ 中,x₁ 对 y 的 边际效应 是 ∂y/∂x₁=w₁+w₃x₂——即 依赖于 x₂ 的取值 。若 w₃ 显著,说明两个特征存在 协同或拮抗 作用(例如'广告投放的回报取决于用户年龄')。 多项式项 (x²、x³…)用于捕捉非线性:单变量情况下它把线性模型提升为多项式回归,可拟合任意光滑曲线。 过拟合风险与对策 :① 数值不稳定 ——x 的取值范围随幂次急剧扩大(x=10 时 x⁵=10⁵),导致设计矩阵病态;对策是先 中心化 (减均值)与 标准化 (除标准差),使各幂次量级相近;② 参数爆炸 ——p 个特征的 d 阶组合数为 C(p+d,d),d=3、p=100 时达 17 万项;对策是 只加有领域意义的交互 、用 正则化 (L1/L2)或 特征选择 筛选;③ 多重共线性 ——x 与 x² 高度相关(尤其 x 全为正时),导致系数方差爆炸;中心化能显著缓解(中心化后 x 与 x² 的相关性降为 0,若 x 对称);④ 外推危险 ——多项式在训练数据范围外会急剧发散,故 不可外推 。
  • 实践建议与替代方案:① 中心化是必须的 ——构造交互项与多项式项前应中心化(有时也称'正交多项式'),这既改善数值条件又使系数更可解释(主效应在'其他变量取均值时'的意义)。② 树模型与深度学习的替代 ——树模型自动学习交互与非线性(无需手工构造),深度学习用隐藏层与注意力隐式建模交互;故 手工构造主要针对线性模型 。③ 正则化的必要性 ——加入大量交互/多项式后必须用 L1(选择有用项)、L2(收缩)或弹性网;实践中常配合 分层建模 (先加主效应,再逐步加交互,用 CV 验证每一步的增益)。④ 分箱替代多项式 ——对有非线性的特征,分箱(等频/有监督)比高次多项式更稳健(抗异常值、可解释),是风控评分卡的常用做法。⑤ 交互项的选择 ——优先用领域知识(如'价格/收入'比、'BMI')而非盲目生成全部交互;也可用树模型的重要度或 SHAP 交互值 发现 值得加入的交互项。⑥ 诊断 ——用偏残差图(partial residual plot)观察非线性是否被捕捉、用 VIF 检查共线。
  • 交互项使 x₁ 的边际效应变为 w₁+w₃x₂(依赖 x₂)
  • 多项式项会导致数值范围急剧扩大

常见陷阱

  • 用高次多项式而不中心化(数值不稳 + 共线)
  • 盲目生成全部交互项而不做正则化