Exercises — Simple linear regression model
This page is a self-testing ladder. Every problem stands alone: read it, cover the solution, try it, then reveal. The rungs climb from "can you spot the pieces?" (L1) to "can you invent and defend a model choice?" (L5).
Everything here uses only tools built in the parent note: the model , the OLS formulas, and the evaluation metrics and RMSE. Nothing new is assumed — where a symbol reappears, we restate what it means so you never hit a wall.
Here (say "x-bar") is just the average of the values, and the average of the values. A residual is the vertical gap between a real point and the line's prediction — picture a little spring pulling the line toward the point.

Level 1 — Recognition
Goal: identify the parts of the model and read a fitted line. No heavy arithmetic.
Exercise L1.1
A fitted model is . (a) What is the slope? (b) What is the intercept? (c) If increases by , how much does change?
Recall Solution
Compare to . (a) Slope (the number multiplying ). (b) Intercept (the standalone number, the value of when ). (c) A one-unit rise in multiplies through the slope: increases by .
Exercise L1.2
For the same model , predict when .
Recall Solution
Substitute : .
Exercise L1.3
Which of these is the residual for a point with prediction ? (i) (ii) (iii)
Recall Solution
(ii) . The residual is the vertical miss: the actual value minus what the line predicted. Option (i) is the part the model explains; option (iii) is the total deviation from the mean. (These three are the pieces of the story.)
Level 2 — Application
Goal: run the OLS machine end-to-end on small datasets.
Exercise L2.1
Fit a line to these 3 points by OLS: . Find and .
Recall Solution
Means: , . Build the deviation columns:
| product | |||||
|---|---|---|---|---|---|
| 1 | 2 | ||||
| 2 | 2 | ||||
| 3 | 5 | ||||
| Σ |
Slope: . Intercept: . Model: .
Exercise L2.2
Using the model from L2.1, compute each residual and confirm they sum to (approximately) zero.
Recall Solution
Predictions: . Residuals : Sum: . ✅ Why zero? The OLS equation forces — that is exactly the condition "the line passes through the center of the data".
Exercise L2.3
Fit an OLS line to .
Recall Solution
, .
| product | square | ||
|---|---|---|---|
| Σ |
, . Model: .
Level 3 — Analysis
Goal: measure fit, interpret coefficients, and probe sensitivity.
Exercise L3.1
For the L2.1 model on , compute .
Recall Solution
RSS (from the residuals in L2.2): . TSS = with : . Reading it: the line explains of the variance in ; the remaining is scatter the straight line cannot capture.
Exercise L3.2
A model of exam score on study hours gives (score in points, in hours). (a) Interpret the slope in words. (b) Interpret the intercept — and say why it may be dubious.
Recall Solution
(a) Each extra hour of study is associated with a -point higher predicted score. (b) is the predicted score at hours (base/prior knowledge). It is dubious if lies outside the observed range of study hours — predicting there is extrapolation (see 2.5-Assumptions-and-Diagnostics).
Exercise L3.3
Two datasets are fit. Dataset A has RMSE ; dataset B has RMSE , but B's values are measured in the thousands while A's are single digits. Can you conclude A's model is better? RMSE is defined .
Recall Solution
No. RMSE carries the units of . An error of on values in the thousands may be relatively tiny, while an error of on single-digit values may be huge. To compare across scales, use a unitless metric like , or normalise RMSE by the range/mean of .
Exercise L3.4
In the L2.3 fit , the point is nudged to . Without a full recompute, will the slope increase or decrease? Then verify by recomputing.
Recall Solution
Prediction: sits far above the old line at the largest . High- points act as levers (they have large ), so pulling this one up should increase the slope. Verify: new , still.
| product | square | ||
|---|---|---|---|
| Σ |
— up from , confirming the prediction.
Level 4 — Synthesis
Goal: combine derivation, algebra, and interpretation into one argument.
Exercise L4.1
Prove algebraically that the OLS line always passes through the mean point .
Recall Solution
Evaluate the fitted line at : Substitute the intercept formula : So the point lies exactly on the line — for any dataset. This is the algebraic face of "the residuals sum to zero" (see figure s02).
Exercise L4.2
Show that if you rescale every to (with constant ), the new slope is , while the intercept is unchanged.
Recall Solution
The mean rescales too: , so . The 's are untouched. Numerator of the slope: . Denominator: . Intercept: Unchanged. ✅ Meaning: converting from, say, metres to centimetres () shrinks the slope by but leaves predictions and the intercept identical — the model is the same line, just relabelled.
Exercise L4.3
A dataset gives , , and for house price vs size. A colleague predicts the price of a mansion whose size is four times the largest house in the data. Give a two-part critique: (i) is the arithmetic valid? (ii) is the conclusion trustworthy?
Recall Solution
(i) Arithmetic: yes — returns a finite number for any ; the formula never fails. (ii) Conclusion: not trustworthy. This is extrapolation far outside the observed range. The linearity assumption was only ever supported inside the data; luxury pricing dynamics may differ entirely. A high on the fitted range gives zero guarantee out there. The honest move: report the prediction with a loud caveat, or gather data covering that range.
Level 5 — Mastery
Goal: derive, decide, and defend under an open-ended prompt.
Exercise L5.1
Derive the OLS intercept and slope for the special case of a single relationship type: suppose all data lie perfectly on a line, i.e. exactly for every . Show OLS recovers and , and that .
Recall Solution
With , the mean is , so . Slope: Intercept: . : every prediction , so every residual is , giving and . OLS reproduces the exact line — as it must when there is no noise.
Exercise L5.2 (Degenerate case)
What does OLS do when every is identical (all data at )? Explain both the algebra and the geometry.
Recall Solution
If all then and every deviation . Denominator: . The slope formula becomes — undefined. Geometry: all points sit on a single vertical strip. Infinitely many lines pass through that strip's mean point with equally "best" vertical fit — there is no unique slope. A vertical spread of is required to pin a slope down. Takeaway: the model needs . This is the simplest form of a collinearity failure — the multi-feature version haunts 2.2.02-Multiple-Linear-Regression.
Exercise L5.3 (Design & defend)
You have 200 patients' (age, cholesterol) data. A straight-line fit gives , and the residual plot shows a clear U-shape (residuals high for young and old, low in the middle). Argue whether simple linear regression is appropriate here, and propose one concrete next step using only ideas linked from this vault.
Recall Solution
Diagnosis: the U-shaped residuals violate the linearity assumption — a straight line systematically under/over-predicts at the extremes. The low agrees: most variance is unexplained. Simple linear regression is not appropriate as-is. Why it's a real signal, not noise: random noise gives residuals with no pattern; a shape means the model is missing structure (here, curvature). Concrete next steps (all in-vault):
- Confirm the violation with formal residual diagnostics — 2.5-Assumptions-and-Diagnostics.
- Add an term (still a linear model in its coefficients) — a case of 2.2.02-Multiple-Linear-Regression — to capture the curve, while watching for 4.2-Overfitting-vs-Underfitting.
- Consider gradient-based fitting if the design grows — 2.3-Gradient-Descent-for-Linear-Regression.
Recall Self-test checklist
Which formula do you compute first — slope or intercept, and why? ::: Slope first: needs . What does mean in words? ::: The line explains of the variance in ; is unexplained scatter. Why can OLS fail entirely? ::: If (all equal), the slope denominator is — undefined. What does a U-shaped residual plot tell you? ::: The linearity assumption is violated; the true relationship is curved.
Parent: Simple linear regression model · Hinglish: 2.2.01 Simple linear regression model (Hinglish)