Can you read the objects and say what each piece is?
Recall Solution 1.1
The "+1" for the intercept column makes the width of X equal to n+1=6.
X: 200×6 — one row per example, one column per feature (plus the 1's).
β: 6×1 — one weight per column of X.
y: 200×1 — one true target per example.
X⊤X: (6×200)(200×6)=6×6 — a square matrix, the thing we invert.
X⊤y: (6×200)(200×1)=6×1 — same shape as β, good sanity check.
The trick: in AB the inner dimensions must match and cancel; the outer two survive. X⊤X being 6×6 (not 200×200) is why the Normal Equation is cheap when features are few.
Recall Solution 1.2
The sign of a coefficient is its direction of effect.
Each row of X is dotted with β. Row i = (1,x(i)), so the dot product is 1⋅3+x(i)⋅2=3+2x(i).
y^=3+2(2)3+2(4)3+2(6)=71115
Notice: with one real feature this is just Simple Linear Regression written in matrix clothing.
Recall Solution 2.2
X⊤=[121416]. Each entry of the product is a dot product of two columns of X.
Top-left = 12+12+12=3 (just counts the examples, m=3).
Off-diagonal = 2+4+6=12 (sum of the feature).
Bottom-right = 22+42+62=4+16+36=56.
X⊤X=[3121256]
For X⊤y:
Inverse of a 2×2 matrix [acbd] is ad−bc1[d−c−ba]. Here the determinant is ad−bc=3(56)−12(12)=168−144=24.
(X⊤X)−1=241[56−12−123]
Multiply by X⊤y=[36164]:
β0=2456(36)−12(164)=242016−1968=2448=2β1=24−12(36)+3(164)=24−432+492=2460=2.5
So β=[22.5], i.e. y^=2+2.5x. (Here m>n, so this is a genuine least-squares fit, not exact.)
Not invertible.x3=3x1 is perfect multicollinearity: one column is an exact linear multiple of another. That makes the columns of X linearly dependent, so X⊤X is singular (determinant 0) — even though m≫n. Having lots of data cannot cure a redundant column.
Geometrically: the model can't tell how to split credit between x1 and x3; infinitely many (β1,β3) pairs give the identical fit.
Fixes: (1) drop the redundant column, or (2) add ridge penalty λI so X⊤X+λI becomes invertible again. Gradient Descent also converges without ever inverting.
Recall Solution 3.2
Residuals=y−y^: (3−2,4−4,5−6)=(1,0,−1).
SSres=12+02+(−1)2=2Total spread of y around its mean yˉ=4: deviations (−1,0,1).
SStot=(−1)2+02+12=2R2=1−22=0
An R2 of 0 means the model does exactly as well as predicting the mean every time — no explanatory power here. See R-squared and Adjusted R-squared.
Ridge replaces X⊤X with X⊤X+λI. Adding λ=1 to the diagonal:
[2+16618+1]=[36619]
Determinant =3(19)−6(6)=57−36=21=0. Invertible! The diagonal "bump" lifts the flat direction that made the original singular. That is exactly why Ridge Regression stabilises multicollinear problems.
Recall Solution 4.2
The model is nonlinear in x but linear in the coefficientsβ0,β1,β2 — and the Normal Equation only cares about linearity in β. So treat x and x2 as two separate feature columns:
X=111123149
(columns: intercept, x, x2). Then β=(X⊤X)−1X⊤y works unchanged. That is the whole idea behind Polynomial Regression.
(a) Build the pieces.
X⊤X=[36614] (since ∑x=6, ∑x2=1+4+9=14).
X⊤y=[∑y∑xy]=[61+6+6]=[613].
Determinant =3(14)−6(6)=42−36=6.
β=61[14−6−63][613]=61[84−78−36+39]=61[63]=[10.5]
So y^=1+0.5x (the red line in the figure).
(b) Fitted values at x=1,2,3: 1.5,2.0,2.5. Residuals y−y^: (1−1.5,3−2.0,2−2.5)=(−0.5,1.0,−0.5). Notice they sum to 0 — the fitted line balances the errors (a property of the least-squares intercept).
(c)y^(5)=1+0.5(5)=3.5.
Recall Solution 5.2
(a) With m=25<n=40, X⊤X is singular, so strictly the inverse doesn't exist — a solver returns a pseudoinverse solution (minimum-norm), which is why you still got numbers. It is one of infinitely many perfect-fit answers.
(b) More unknowns than equations means the plane can thread exactly through every training point → zero residual → R2=1.0. That's memorisation, not learning: textbook Overfitting. Perfect training fit with few examples is a red flag.
(c) (1) Regularise with Ridge Regression to shrink coefficients and pick a stable solution; (2) reduce features / gather more data so m>n; (Gradient Descent with early stopping also helps).
Recall Self-test cloze summary
The Normal Equation is ::: β=(X⊤X)−1X⊤yX⊤X is singular when features are perfectly multicollinear or when ::: there are fewer examples than features (m<n)
The diagonal fix that restores invertibility is called ridge (add λI)
R2=0 means the model does no better than ::: predicting the mean of y every time