Skip to content

Cheatsheet: Fitting a line: linear regression

PieceSymbolMeaning
Equationy = b + m*xprediction = intercept + slope times feature
Slopemchange in prediction per one-unit increase in input
Interceptbprediction when the input is zero
Parametersm, bthe model’s weights; training chooses them
StepWhat you do
1Residual = actual minus predicted, for each point
2Square each residual (errors stay positive; big misses cost more)
3Add them up: the sum of squared residuals (SSR)
4Best-fit line = the one with the smallest possible SSR
LinePer-point squared residualsSSRVerdict
A: y = 1.5x + 0.50.00, 0.25, 0.000.25better fit
B: y = 2x0, 0, 11.00worse fit

(Data points: (1,2), (2,4), (3,5). Lower SSR wins.)

CoefficientReads as
Slope = 0.30each +1 of input predicts +0.30 of output
Intercept = 200predicted output is 200 when input is 0
Negative slopeoutput falls as input rises
Form
Equationy = b + m1*x1 + m2*x2 + m3*x3
Each coefficientchange in output per one-unit change in that feature, others held fixed
Goalsame: minimize the sum of squared residuals
IdeaNote
R-squaredfraction of variation explained, 0 to 1; higher is more
Extrapolationunreliable outside the data’s range
Curved dataa straight line fits a curve poorly
Coefficient as causeslope is association, not causation
Outlierssquaring makes least squares outlier-sensitive