This page is a self-test ladder. Each problem is graded from L1 (just recognise the pieces) up to L5 (mastery — combine ideas you had to build yourself). Every solution is hidden inside a collapsible callout: try first, then reveal.
Before symbols appear, here is the vocabulary you actually need, in plain words and pictures.
Recall the two tools we keep reusing (built fully in the parent note):
X is 5×4 (rows = points, columns = features+bias).
XT is 4×5, so XTX is (4×5)(5×4)=4×4.
XTy is (4×5)(5×1)=4×1.
w solves a 4×4 system so it is 4×1.
Sanity check: the number of unknowns in w (=4) always equals the number of columns of X.
Recall Solution L1.2
(b). (a) is absolute error — kinks make its derivative undefined at 0, so calculus is harder. (c) is not squared, so errors above and below the line cancel; you could have huge errors summing to zero. Squaring in (b) makes every error positive and gives a smooth bowl to slide down.
X=111012,y=133
Top-left of XTX counts the points: 1+1+1=3.
Off-diagonal is ∑xi=0+1+2=3.
Bottom-right is ∑xi2=0+1+4=5.
XTX=[3335]XTy: first entry ∑yi=1+3+3=7; second ∑xiyi=0⋅1+1⋅3+2⋅3=9.
XTy=[79]
Recall Solution L2.2
Determinant: 3⋅5−3⋅3=15−9=6.
(XTX)−1=61[5−3−33]w∗=61[5−3−33][79]=61[35−27−21+27]=61[86]=[1.3331]
So b=34≈1.333, w=1. Line: y^=x+1.333.
Check by eye: at x=1 it predicts 2.333 (true 3), at x=2 predicts 3.333 (true 3) — errors balanced, as least squares demands.
Recall Solution L2.3
Predictions with w0 are all 0, so error Xw0−y=[−1,−3,−3]T.
Gradient ∇J=31XT(Xw0−y):
first entry 31(−1−3−3)=3−7=−2.333
second entry 31(0⋅(−1)+1⋅(−3)+2⋅(−3))=3−9=−3w1=[00]−0.1[−2.333−3]=[0.23330.3]
The normal equation is XTXw∗=XTy. Rearrange:
XTy−XTXw∗=0⇒XT(y−Xw∗)=0⇒XTr=0.Meaning (see figure):Xw∗ is the shadow (projection) of y onto the flat plane spanned by X's columns. The leftover r points straight out of that plane — the shortest possible leftover. Any other w leaves a longer residual.
Recall Solution L3.2
Column 3 =2× column 2, so the columns are linearly dependent. Then XTX is singular (determinant 0) and (XTX)−1 does not exist — the normal equation has infinitely many solutions. Geometrically the "plane" the columns span collapses to a lower dimension, so y's projection is well-defined but the coordinatesw that reach it are not unique. This is multicollinearity. Fixes: drop a redundant feature, or add Ridge which replaces XTX with XTX+λI (always invertible for λ>0), or use the Matrix Pseudoinverse which picks the minimum-norm solution.
Recall Solution L3.3
The second derivative (Hessian) of J is n1XTX. For any nonzero direction v, vTXTXv=∥Xv∥2≥0, and it is >0 when the columns are independent. A matrix with all positive curvatures is positive definite, so J is strictly convex — a single bowl. Every downhill path reaches the same bottom, which is why gradient descent cannot get stuck in a fake local minimum here.
X=111123, y=[2,2,4]T.
XTX=[36614], det =42−36=6.
XTy: ∑yi=8; ∑xiyi=2+4+12=18.
w∗=61[14−6−63][818]=61[112−108−48+54]=61[46]=[0.6671]
So b=32,w=1. (ii) Because J is strictly convex (L3.3) and XTX is invertible, gradient descent with small enough α converges to the same unique minimum [0.667,1]T. The two methods must agree — they solve the same equation, one in a jump, one by walking.
Recall Solution L4.2
The curvature in each direction is set by that feature's ∑x2. With ranges 1 vs 10,000 the bowl is a long thin canyon: steep across the small feature, nearly flat along the big one. A single learning rate α must be tiny enough not to overshoot the steep wall — so it barely moves along the flat floor. Result: zig-zagging, glacial convergence. Scaling (e.g. subtract mean, divide by std) makes all ∑x2 comparable, turning the canyon into a round bowl where one α works in every direction. The normal equation is immune (no α), which is one reason it's convenient for small d.
Recall Solution L4.3
Take the gradient and set to zero. The extra term contributes λw:
n1XT(Xw−y)+λw=0.
Multiply through by n and group w:
(XTX+nλI)w=XTy⇒w∗=(XTX+nλI)−1XTy.
Since XTX has eigenvalues ≥0, adding nλI (λ>0) shifts every eigenvalue up by nλ>0 — none can be zero, so the matrix is invertible even under the multicollinearity of L3.2. See Regularization (Ridge, Lasso).
Normal equation is out: forming and inverting XTX (50,000×50,000) costs O(d3)≈1.25×1014 operations plus 2.5×109 entries of memory — infeasible, and it can't ingest a live stream. Full batch GD touches all 2,000,000 rows per step — expensive per iteration. The right choice is mini-batch / SGD: each step uses a small batch (e.g. 256 rows), cost O(bd) per step, and it naturally consumes the stream in real time. Trade-off: noisier steps, so use a decaying α. This is exactly the setting behind Kalman Filtering and online estimators, and mini-batch GD is the workhorse of Neural Networks for the same scaling reason.
Recall Solution L5.2
X=111123, y=[1,2,2]T.
XTX=[36614] (det 6). XTy: ∑y=5, ∑xiyi=1+4+6=11.
w∗=61[14−6−63][511]=61[70−66−30+33]=61[43]=[0.6670.5](ii) Predictions y^=0.5x+0.667: at x=1,2,3 give 1.167,1.667,2.167.
Residuals r=y−y^=[−0.167,0.333,−0.167]T.
∥r∥2=0.0278+0.1111+0.0278=0.1667. Cost J=2⋅31(0.1667)=0.02778.
(iii)XTr: first entry −0.167+0.333−0.167=0; second −0.167+0.667−0.5=0. ✓ Residual is orthogonal to both columns, confirming the projection picture.
Recall Solution L5.3
Convergence needs the contraction factor's magnitude <1:
1−nα∑xi2<1⇒0<3α(14)<2⇒α<146=0.4286.
Above this, α≈0.4286 oscillates without shrinking, and α>0.4286diverges — each step overshoots further than the last. The safe rule: α<∑xi22n (in general, α<2/λmax of the Hessian).
Recall Self-test cloze
The normal equation solution is ::: w∗=(XTX)−1XTy
Gradient descent diverges when α exceeds ::: 2/λmax of the Hessian n1XTX
Ridge stays invertible because it adds ::: nλI, lifting every eigenvalue above zero
At the optimum the residual is ::: orthogonal to every column of X (XTr=0)