Least Squares Line Fitting

EEC 351 · Fundamentals of AI/ML · Prof. Parikshit Pareek & Prof. Jitin Singla · IIT Roorkee

Given n points (xi, yi), the ordinary least squares (OLS) line minimises the sum of squared vertical distances from each point to the line. The minimiser has a closed form: β̂ = (X⊤X)−1X⊤y. Click to add data points and watch the line — and the matrix arithmetic — update live.

β̂ = arg minβ ‖y − Xβ‖22,   X = [x | 1],   β̂ = (X⊤X)−1X⊤y
Preset:
data points OLS fit residuals mean (x̄, ȳ)
Click anywhere to add a point. Click on an existing point to remove it.

Display options

Fitted line

n = 0 points
—
Slope m = —
Intercept c = —

Error metrics

SSR = Σri2 = —
RMSE = √(SSR/n) = —
R2 = 1 − SSR/SST = —

Normal equations

X⊤X =
X⊤y =
β̂ = (X⊤X)−1X⊤y =

What to notice during class