core practice · coding problem
Fit a simple linear regression
Points: (1, 2), (2, 3), (3, 5). Fit y = a + bx by least squares. Compute a, b, and the predicted ŷ at x = 4.
The mechanism
Linear regression finds the best linear predictor — geometrically, it projects the target vector onto the column space of your features. Least squares minimizes squared error, which is why outliers pull the line hard.
Expected evidence
b ≈ 1.5, a ≈ 0.17, ŷ(4) ≈ 6.17. (Exact: b = 3/2, a = 1/6.)
Try this drill in the practice workspace →
Hints when you need them
- b = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)².
- a = ȳ − b·x̄.
Watch for these mistakes
- Extrapolating far outside the training range
- Treating high R² as proof of causation
- Ignoring multicollinearity among features