2.2.1 · D5Linear & Logistic Regression
Question bank — Simple linear regression model
This is a rapid-fire self-test for the parent topic. Each line is a question ::: answer reveal. Cover the right side, say your reasoning out loud, then check. The answers are never a bare "yes/no" — they carry the why, because that is the part exams and interviews actually probe.
True or false — justify
True or false: OLS minimizes the sum of vertical distances from points to the line.
False. It minimizes the sum of squared vertical distances (RSS). Plain distances would let a and a error cancel to zero, hiding a bad fit; squaring keeps every error positive and punishes big misses harder.
True or false: The OLS best-fit line always passes through the point .
True. The intercept formula rearranges to , which literally says the line hits the mean-point. This is a direct consequence of the residuals summing to zero.
True or false: If , then and are independent.
False. only means there is no linear trend. A U-shaped relationship ( high at both extremes of ) can have zero slope yet be strongly, deterministically related — the line just cannot see curved structure.
True or false: A higher always means a better model.
False. measures variance explained on the data you fit, not predictive skill. Adding noise features or overfitting can inflate it while generalization worsens — see 4.2-Overfitting-vs-Underfitting.
True or false: can be negative.
True, but not for the OLS line on its training data. If you evaluate some other line (or a model on new data) that predicts worse than the flat line , then RSS exceeds TSS and drops below zero.
True or false: The residuals from an OLS fit always add up to zero.
True (when the model has an intercept). Setting is exactly the equation . Without an intercept term this guarantee disappears.
True or false: Swapping the roles of and gives a line with slope .
False. Regressing on minimizes horizontal squared errors, giving slope , not . The two lines only coincide when the fit is perfect ().
True or false: RMSE and always rank two models the same way.
True for models compared on the same dataset, since and RMSE both move monotonically with RSS. Across different datasets they can disagree because TSS and change.
True or false: If all data points lie exactly on a horizontal line, and .
False on the part. Here has zero variance, so TSS and is undefined. The slope is genuinely , but "fraction of variance explained" is meaningless when there is no variance.
True or false: The error term and the residual are the same thing.
False. is the true, unobservable noise around the real relationship; is our estimated leftover using the fitted line. We only ever see residuals and hope they behave like the errors.
Spot the error
"Intercept means a 0-square-foot house is worth $50k, so land alone costs $50k."
The number is real but the meaning is invented. is far outside the observed range (extrapolation), where linearity need not hold; is a mathematical anchor, not a validated price.
"My slope came out negative, so I must have made a sign mistake — slopes are positive."
Nothing is wrong. A negative simply means decreases as increases (e.g. price vs mileage). The sign of matches the sign of , which can legitimately be negative.
"Ice-cream sales predict drownings with , so banning ice cream will save lives."
The error is reading causation into correlation. Summer heat is a confounding variable driving both; the regression captures association only. See 2.5-Assumptions-and-Diagnostics.
"I dropped the point with the biggest residual because the model fits better without it."
A large residual is not automatically an "error" — it may be a real, informative observation. Deleting points to improve fit is data-massaging; investigate why it is far off before removing anything.
", so 80% of my predictions are correct."
is variance explained, not an accuracy percentage. It says the model accounts for 80% of the spread in , which is not a count of right-vs-wrong predictions.
"I added the residuals, got zero, and concluded my model is perfect."
Residuals summing to zero is guaranteed for any intercept model, good or terrible. It tells you nothing about fit quality; you need RSS, RMSE, or a residual plot instead.
" from the covariance formula."
Wrong denominator. The slope divides by , i.e. . Using would give the slope of the reversed regression.
Why questions
Why do we square residuals instead of taking absolute values?
Squaring makes RSS smooth and differentiable, so calculus gives a clean closed-form solution; absolute value has a non-differentiable kink at zero. Squaring also penalizes large errors more heavily, pulling the line away from big misses.
Why does setting the derivative to zero give the minimum and not a maximum?
RSS is a sum of squared terms, so as it grows without bound — an upward-opening bowl (parabolic in each parameter). A single flat point on such a shape must be its lowest point.
Why must we subtract the means before computing the slope (the terms)?
Centering isolates how and co-vary around their typical values, stripping out the constant offset that the intercept already handles. This turns the messy normal equations into the clean covariance-over-variance form.
Why is RMSE often preferred over RSS when reporting error?
RSS grows with sample size and is in squared units, so it is hard to interpret. RMSE divides by and takes a square root, landing back in the original units of ("off by about ±RMSE on average").
Why does the homoscedasticity assumption matter if the OLS formula ignores it?
The formula still computes a line, but equal error variance is what makes OLS the best unbiased estimator and makes standard errors and confidence intervals trustworthy. Violate it and the point estimate survives but your uncertainty claims break.
Why can two people fit lines to the same points and, both being "correct," disagree on the slope?
If one regresses on and the other on , they minimize different distances (vertical vs horizontal). Both are valid OLS fits of different questions and only agree when the correlation is perfect.
Why does gradient descent even exist if OLS has a closed-form answer?
For one feature the closed form is trivial, but with many features (see 2.2.02-Multiple-Linear-Regression) the matrix inverse becomes expensive or unstable. 2.3-Gradient-Descent-for-Linear-Regression scales far better, which is why neural nets and 3.1-Logistic-Regression-Model rely on it.
Edge cases
What happens to the slope formula if every is identical?
The denominator , so is undefined (division by zero). Geometrically all points sit on a vertical line, which no function can represent.
What is when the model is the flat line (a "do-nothing" predictor)?
RSS then equals TSS, so . This is the baseline: means "no better than just guessing the mean."
With only two data points, what does OLS produce?
A line passing exactly through both points, giving RSS and . Perfect fit here is meaningless — two points always determine a line, so there is no evidence the relationship is real.
If all are the same but the vary, what are and ?
gives , and , so the fit is a flat line at that constant. But is undefined since TSS (no variance in to explain).
For a single data point, is the model defined?
No. With , so the slope denominator is zero, and infinitely many lines pass through one point. You cannot estimate a trend from one observation.
Does OLS behave differently for a negative slope than a positive one?
No — the identical formula handles both; the sign simply follows . There is no separate "case," which is why we never branch on the sign the way angle formulas branch on quadrants.
Recall Fastest possible summary
The line always hits ; residuals sum to zero for free; is variance explained (undefined when has no variance, negative for bad non-OLS predictors); slope is undefined when has no spread; and "the line fits" never proves " causes ."