Linear Models & Optimization
Linear regression, regularization (L1/L2/Elastic Net), the closed-form OLS solution and its pitfalls, and gradient-based optimization.
18 questions
JuniorTheoryVery commonWhich assumptions does linear regression make, and which one invalidates its p-values?
Which assumptions does linear regression make, and which one invalidates its p-values?
Linearity in the parameters, independent errors, constant variance, roughly normal residuals. Heteroscedasticity or correlated errors leave coefficients unbiased but break the standard-error formula, so p-values need robust errors.
Common mistakes
- ✗Requiring the features themselves to be normal instead of the residuals
- ✗Treating every assumption as equally critical for prediction and inference
- ✗Not knowing robust standard errors repair inference under heteroscedasticity
Follow-up questions
- →Why does the central limit theorem make the normality assumption mild on large samples?
- →Which assumption breaks first on time-series data, and what does that do to inference?
JuniorTheoryVery commonHow is one regression coefficient interpreted, and when does that reading break?
How is one regression coefficient interpreted, and when does that reading break?
A coefficient is the expected change in the target per one-unit rise in that feature with others held fixed. Correlated features make that clause unobservable and destabilize signs; unequal scales make magnitudes incomparable, so standardize.
Common mistakes
- ✗Reading a coefficient as a causal effect rather than a conditional association
- ✗Ranking feature importance by raw coefficient size across different units
- ✗Fitting Ridge or Lasso on unscaled columns so the penalty lands unevenly
Follow-up questions
- →Why does a penalty applied to unscaled columns punish small-scale features hardest?
- →What does an inflated coefficient variance tell you about a pair of correlated columns?
JuniorTheoryVery commonWhy is a binary label fitted with logistic regression instead of linear regression?
Why is a binary label fitted with logistic regression instead of linear regression?
A linear fit is unbounded, so it predicts probabilities below zero or above one and is skewed by far-off points. Logistic regression squashes the score through a sigmoid into a log-odds model and trains on convex log-loss.
Common mistakes
- ✗Reading a raw linear score as a probability without any bounding
- ✗Thinking log-loss is picked for convenience rather than convexity
- ✗Assuming squared error on a sigmoid output trains just as well
Follow-up questions
- →What does the linear part of the model predict on the log-odds scale?
- →Why does squared error on a sigmoid output starve the gradient when a prediction is confidently wrong?
JuniorTheoryCommonWhich modifications of gradient descent do you know?
Which modifications of gradient descent do you know?
Common variants: SGD with momentum (accumulates past gradients), AdaGrad (per-parameter adaptive step), RMSProp (AdaGrad with a decaying average against step collapse), Adam (momentum + RMSProp) and Adan. They differ in how they adapt the step size and smooth the gradient direction.
Common mistakes
- ✗Confusing optimizer variants with regularization techniques
- ✗Thinking Adam is unrelated to momentum and RMSProp rather than combining them
- ✗Believing RMSProp and AdaGrad are unrelated rather than RMSProp refining AdaGrad
Follow-up questions
- →What does momentum add over plain SGD?
- →Why does RMSProp fix AdaGrad's vanishing step-size problem?
JuniorTheoryCommonHow is linear regression usually solved in practice?
How is linear regression usually solved in practice?
With gradient-based optimization, not the closed-form matrix formula. The staples are full-batch gradient descent (GD), which uses all samples per step, and stochastic gradient descent (SGD), which uses one sample or a mini-batch. SGD scales to large data and is the usual default.
Common mistakes
- ✗Assuming the closed-form formula is what production systems actually run
- ✗Not distinguishing full-batch GD from stochastic/mini-batch SGD
- ✗Thinking SGD is only an approximation used when GD is unavailable
Follow-up questions
- →Why is the closed-form solution avoided despite being exact?
- →When would you prefer mini-batch SGD over full-batch GD?
JuniorTheoryCommonWhat exactly is naive about Naive Bayes, and why does it still work on text?
What exactly is naive about Naive Bayes, and why does it still work on text?
It assumes features are conditionally independent given the class, which words are not. It survives because classification needs only the right argmax, not calibrated probabilities — correlated words lift every class score alike.
Common mistakes
- ✗Thinking the naive assumption is about the class prior rather than feature independence
- ✗Expecting its output probabilities to be well calibrated
- ✗Concluding that a false assumption must make the classifier useless
Follow-up questions
- →Why can a badly calibrated score still produce the right class decision?
- →What does additive smoothing fix when a word is unseen for one class?
JuniorTheoryCommonWhat is regularization, and which kinds apply to linear models?
What is regularization, and which kinds apply to linear models?
Regularization fights overfitting by adding a weight-norm penalty to the optimization objective. For linear models: L1 (sum of absolute weights), L2 (sum of squared weights), and Elastic Net (a mix of L1 and L2). The penalty discourages overly large weights.
Common mistakes
- ✗Confusing regularization (a penalty term) with feature scaling or feature selection
- ✗Thinking L1 and L2 differ only in scale, not in their effect on sparsity
- ✗Believing Elastic Net is a separate algorithm rather than a weighted sum of L1 and L2 penalties
Follow-up questions
- →Which of L1 and L2 drives weights exactly to zero, and why?
- →Should the bias/intercept term be included in the penalty?
JuniorTheoryCommonHow do you read a residual plot, and what do a funnel shape and a curve mean?
How do you read a residual plot, and what do a funnel shape and a curve mean?
Plot residuals against fitted values — healthy is a shapeless band around zero. A widening funnel means error variance grows with the prediction, so transform the target or use robust errors. A curve means the form is misspecified.
Common mistakes
- ✗Plotting residuals against the target instead of the fitted values
- ✗Reading a funnel as a sign of missing features rather than unequal variance
- ✗Ignoring curvature because the overall error metric still looks acceptable
Follow-up questions
- →Which assumption does the funnel shape specifically falsify?
- →Why does a log transform of the target often flatten a funnel?
MiddleTheoryCommonWhat does a generative model learn versus a discriminative one, and who wins on tiny data?
What does a generative model learn versus a discriminative one, and who wins on tiny data?
A generative model learns the joint distribution — class prior plus per-class feature distribution — and derives the posterior. A discriminative one fits the boundary directly. Naive Bayes hits its higher asymptotic error sooner and wins on tiny data.
Common mistakes
- ✗Swapping the two definitions and calling the boundary learner generative
- ✗Assuming the small-sample winner is also the large-sample winner
- ✗Believing a generative model must always be able to synthesize realistic inputs
Follow-up questions
- →Which of the two would you pick once labelled data become plentiful, and why?
- →What extra thing can a generative model do that a boundary learner cannot?
MiddleTheoryCommonWhat is the closed-form OLS solution, and why is it avoided in practice?
What is the closed-form OLS solution, and why is it avoided in practice?
Minimizing the squared error gives w = (XᵀX)⁻¹Xᵀy. It is avoided because inverting XᵀX is costly on many features, and XᵀX may be singular or ill-conditioned, so the inverse is impossible or numerically unstable. Adding λI fixes the conditioning; gradient methods are preferred.
Common mistakes
- ✗Misremembering the formula (wrong placement of the transpose or inverse)
- ✗Citing only the inversion cost and forgetting the singularity/ill-conditioning problem
- ✗Not knowing that regularization restores invertibility via
λI
Follow-up questions
- →What is the computational complexity of the matrix inversion involved?
- →How exactly does adding
λImakeXᵀXinvertible?
MiddleTheoryCommonWhy does penalizing the weight norm help fight overfitting?
Why does penalizing the weight norm help fight overfitting?
A symptom of overfitting is very large weights. With huge weights, two near-identical inputs differing by epsilon can yield wildly different predictions — the function is unstable. Penalizing the norm shrinks weights toward zero, giving a smoother, lower-variance function that generalizes better.
Common mistakes
- ✗Thinking the penalty improves the fit on the training set rather than restraining it
- ✗Not connecting large weights to output hypersensitivity on nearby inputs
- ✗Assuming any weight reduction helps, ignoring that the goal is a smoother decision function
Follow-up questions
- →What concretely is the symptom of overfitting that the penalty targets?
- →Does shrinking weights increase bias, and is that an acceptable trade?
MiddleTheoryCommonWhat is SGD with momentum, and when does it speed up convergence?
What is SGD with momentum, and when does it speed up convergence?
Momentum keeps an exponentially-weighted sum of recent gradients and steps along it, damping oscillations. It helps most on elongated (ill-conditioned) level curves: the gradient points across the valley, so plain SGD zig-zags, while momentum averages the swing out and moves along the valley.
Common mistakes
- ✗Describing momentum as a fixed direction rather than a decaying running average
- ✗Not naming elongated/ill-conditioned level curves as the case it helps most
- ✗Confusing the oscillation-damping effect with simply raising the learning rate
Follow-up questions
- →Why is the gradient perpendicular to the level curves, and why does that cause zig-zag?
- →How does Adam build on the momentum idea?
SeniorTheoryCommonWhy does L1 regularization produce sparse weights while L2 does not?
Why does L1 regularization produce sparse weights while L2 does not?
Geometrically L1's constraint is a diamond with corners on the axes; the loss level-set usually touches a corner, where a weight is 0. L2's is a circle with no corners. By gradient, L1's |∂R/∂w| is constant so descent reaches 0, while L2's shrinks as w→0 and weights stop short.
Common mistakes
- ✗Swapping the shapes — calling L1 the circle and L2 the diamond
- ✗Explaining only the geometry and missing the constant-vs-shrinking gradient argument
- ✗Claiming L2 also zeroes weights, just more slowly
Follow-up questions
- →At a corner of the diamond, what is true about the loss and penalty gradients?
- →Why is the L1 objective non-differentiable on the axes, and does that block descent?
JuniorTheoryOccasionalIn a support vector machine, what are the margin and support vectors, and what does C control?
In a support vector machine, what are the margin and support vectors, and what does C control?
The margin is the band between the hyperplane and the nearest points, and training maximizes its width. Support vectors are the points on or violating it — only they define the solution. Large C narrows the margin, small C widens it.
Common mistakes
- ✗Believing every training point is a support vector
- ✗Reading large C as stronger regularization instead of weaker
- ✗Confusing the margin with the distance between class centroids
Follow-up questions
- →Why does removing a non-support vector leave the fitted boundary unchanged?
- →Which value of C would you reach for when the training data are noisy?
MiddleDebuggingOccasionalWhy do logistic-regression coefficients blow up on separable data, and what stops it?
Why do logistic-regression coefficients blow up on separable data, and what stops it?
Under perfect separation the maximum-likelihood optimum does not exist — scaling the weights up pushes log-loss toward zero without reaching it, so they diverge and the solver stops only on its iteration cap. A penalty pins a finite solution.
Open full question →Common mistakes
- ✗Raising max_iter and treating the vanished warning as a fix
- ✗Blaming float overflow or feature scale instead of a non-existent optimum
- ✗Assuming perfect training accuracy means the fit is healthy
Follow-up questions
- →Why does raising the iteration cap make the printed coefficients larger, not stabler?
- →Besides a penalty, which other remedy bounds the estimate under separation?
MiddleTheoryOccasionalShould the bias/intercept term be included in the regularizer?
Should the bias/intercept term be included in the regularizer?
No. The intercept only shifts the hyperplane to where the data sits; it is not a weight on a feature. Penalizing it pulls the offset toward zero and stops the model from positioning the hyperplane well, so quality gets worse. By convention the bias is excluded from the penalty.
Common mistakes
- ✗Treating the intercept like any other weight that needs shrinking
- ✗Not realizing the bias positions the hyperplane rather than scaling a feature
- ✗Assuming including w0 is harmless when it usually degrades quality
Follow-up questions
- →What does the bias control geometrically that the feature weights do not?
- →How do libraries typically implement this exclusion in practice?
SeniorTheoryRareWhat is the computational complexity of inverting an n×n matrix?
What is the computational complexity of inverting an n×n matrix?
The standard algorithm (Gauss–Jordan / LU) is cubic, O(n³). Strassen-style multiplication gives about O(n^2.81), and asymptotically faster ones exist but carry huge constants and practical constraints, so they are rare. This cubic cost is why closed-form OLS is avoided.
Common mistakes
- ✗Saying inversion is
O(n²)by counting matrix entries rather than operations - ✗Believing fast algorithms like Strassen are used by default in production libraries
- ✗Confusing the cost of one matrix-vector multiply with the cost of full inversion
Follow-up questions
- →Why aren't sub-cubic algorithms used by default despite the better asymptotics?
- →How does this cost motivate gradient methods for large feature spaces?