When would you prefer an iterative solver over the closed-form Normal Equation?

Quick Overview

Explain when an iterative solver such as gradient descent is a better way to fit a linear regression than the closed-form Normal Equation. Tests reasoning about computational cost in rows and features, memory, numerical conditioning, sparse data and streaming updates.

When would you prefer an iterative solver over the closed-form Normal Equation?

Role: Data Scientist

Category: Machine Learning

Difficulty: medium

Interview Round: Other

When fitting a linear regression, when would you prefer an iterative solver over the closed-form Normal Equation? ```hint Count the cost Write the cost of forming and solving the normal equations in terms of the number of rows $n$ and the number of features $p$, then compare it with the cost of one gradient step. ``` ```hint Conditioning cuts both ways Collinear features cause trouble for the closed-form solve. Ask what they also do to the speed at which gradient descent converges. ``` ### What a Strong Answer Covers - The time and memory cost of the closed form as a function of $n$ and $p$, compared with an iterative method - Which dimension, rows or features, actually limits the closed form, including the case where the data does not fit in memory - How ill-conditioning affects each approach and what fixes it - Settings that favor iterative methods, such as sparse high-dimensional features, streaming data, or losses with no closed form - When the closed form remains the better choice ### Follow-up Questions - Why do numerical libraries solve least squares with a QR or SVD factorization instead of computing the inverse of $X^\top X$? - How does the condition number of $X^\top X$ affect the number of gradient descent iterations, and what can you do about it? - How would you fit a linear regression on 2 billion rows with 50 features? - Does adding an L2 penalty change which approach you would pick? What about an L1 penalty?

Overview: Explain when an iterative solver such as gradient descent is a better way to fit a linear regression than the closed-form Normal Equation. Tests reasoning about computational cost in rows and features, memory, numerical conditioning, sparse data and streaming updates.

PracHub logo
General
Nov 24, 2026
mediumData ScientistOtherMachine Learning
0
0

When fitting a linear regression, when would you prefer an iterative solver over the closed-form Normal Equation?

What a Strong Answer Covers Guidance

  • The time and memory cost of the closed form as a function of nn and pp , compared with an iterative method
  • Which dimension, rows or features, actually limits the closed form, including the case where the data does not fit in memory
  • How ill-conditioning affects each approach and what fixes it
  • Settings that favor iterative methods, such as sparse high-dimensional features, streaming data, or losses with no closed form
  • When the closed form remains the better choice

Follow-up Questions Guidance

  • Why do numerical libraries solve least squares with a QR or SVD factorization instead of computing the inverse of X⊤XX^\top X ?
  • How does the condition number of X⊤XX^\top X affect the number of gradient descent iterations, and what can you do about it?
  • How would you fit a linear regression on 2 billion rows with 50 features?
  • Does adding an L2 penalty change which approach you would pick? What about an L1 penalty?