Yeh page ek self-test ladder hai. Har problem L1 (bas pieces ko pehchano) se lekar L5 (mastery — khud banaye hue ideas ko combine karo) tak graded hai. Har solution ek collapsible callout ke andar chhupa hua hai: pehle khud try karo, phir reveal karo.
Symbols aane se pehle, yeh woh vocabulary hai jo tumhe actually chahiye — simple words aur pictures mein.
Un do tools ko yaad karo jo hum baar baar use karte hain (parent note mein fully banaye gaye hain):
X ka shape hai 5×4 (rows = points, columns = features+bias).
XT ka shape hai 4×5, isliye XTX hai (4×5)(5×4)=4×4.
XTy hai (4×5)(5×1)=4×1.
w ek 4×4 system solve karta hai isliye yeh 4×1 hai.
Sanity check:w mein unknowns ki sankhya (=4) hamesha X ke columns ki sankhya ke barabar hoti hai.
Recall Solution L1.2
(b). (a) absolute error hai — kinks ki wajah se 0 par iski derivative undefined hoti hai, isliye calculus mushkil ho jaati hai. (c) squared nahi hai, isliye line ke upar aur neeche ke errors cancel ho jaate hain; tumhare paas huge errors ho sakte hain jo sum karke zero ho jaayein. (b) mein squaring har error ko positive banati hai aur ek smooth bowl deti hai jisme slide kiya ja sake.
Aankhon se check karo:x=1 par yeh 2.333 predict karta hai (actual 3), x=2 par 3.333 predict karta hai (actual 3) — errors balanced hain, jaise least squares demand karta hai.
Recall Solution L2.3
w0 ke saath predictions sab 0 hain, isliye error Xw0−y=[−1,−3,−3]T.
Gradient ∇J=31XT(Xw0−y):
Normal equation hai XTXw∗=XTy. Rearrange karo:
XTy−XTXw∗=0⇒XT(y−Xw∗)=0⇒XTr=0.Matlab (figure dekho):Xw∗, X ke columns se bane flat plane par y ka shadow (projection) hai. Bacha hua r us plane se seedha bahar point karta hai — possible mein se sabse chhota bacha hua. Koi bhi doosra w zyada lamba residual chhod deta hai.
Recall Solution L3.2
Column 3 =2× column 2, isliye columns linearly dependent hain. Tab XTXsingular hai (determinant 0) aur (XTX)−1 exist nahi karta — normal equation ke infinitely many solutions hain. Geometrically woh "plane" jo columns span karte hain ek lower dimension mein collapse ho jaata hai, isliye y ka projection well-defined hai lekin coordinatesw jo usse reach karte hain unique nahi hain. Yeh multicollinearity hai. Fixes: ek redundant feature drop karo, ya Ridge add karo jo XTX ko XTX+λI se replace karta hai (λ>0 ke liye hamesha invertible), ya Matrix Pseudoinverse use karo jo minimum-norm solution deta hai.
Recall Solution L3.3
J ki second derivative (Hessian) hai n1XTX. Kisi bhi nonzero direction v ke liye, vTXTXv=∥Xv∥2≥0, aur yeh >0 hota hai jab columns independent hon. Ek matrix jisme sab positive curvatures hon woh positive definite hai, isliye J strictly convex hai — ek single bowl. Har downhill path same bottom tak pahunchta hai, isliye gradient descent yahan kisi fake local minimum mein stuck nahi ho sakta.
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]
Toh b=32,w=1. (ii) Kyunki J strictly convex hai (L3.3) aur XTX invertible hai, gradient descent kaafi chhote α ke saath same unique minimum [0.667,1]T par converge karta hai. Dono methods agree karne chahiye — woh same equation solve karte hain, ek jump mein, ek walk karke.
Recall Solution L4.2
Har direction mein curvature us feature ke ∑x2 se set hoti hai. 1 vs 10,000 ranges ke saath bowl ek lamba patla canyon hai: chhote feature ke across steep, bade wale ke along almost flat. Ek single learning rate α itni chhoti honi chahiye ki steep wall ko overshoot na kare — isliye flat floor ke saath barely move karta hai. Result: zig-zagging, glacial convergence. Scaling (jaise mean subtract karo, std se divide karo) sab ∑x2 ko comparable banata hai, canyon ko ek round bowl mein badal deta hai jahan ek α har direction mein kaam karta hai. Normal equation immune hai (koi α nahi), jo ek reason hai ki chhote d ke liye yeh convenient hai.
Recall Solution L4.3
Gradient lo aur zero set karo. Extra term λw contribute karta hai:
n1XT(Xw−y)+λw=0.n se multiply karo aur w group karo:
(XTX+nλI)w=XTy⇒w∗=(XTX+nλI)−1XTy.
Kyunki XTX ke eigenvalues ≥0 hain, nλI (λ>0) add karne se har eigenvalue nλ>0 se upar shift ho jaata hai — koi bhi zero nahi ho sakta, isliye matrix invertible hai chahe L3.2 ki multicollinearity ho. Regularization (Ridge, Lasso) dekho.
Normal equation out hai: XTX (50,000×50,000) form karna aur invert karna O(d3)≈1.25×1014 operations plus 2.5×109 memory entries cost karta hai — infeasible hai, aur yeh live stream ingest nahi kar sakta. Full batch GD har step mein 2,000,000 rows touch karta hai — per iteration expensive hai. Sahi choice hai mini-batch / SGD: har step ek small batch use karta hai (jaise 256 rows), cost O(bd) per step, aur yeh naturally real time mein stream consume karta hai. Trade-off: noisier steps, isliye decaying α use karo. Yeh exactly wahi setting hai Kalman Filtering aur online estimators ke behind, aur mini-batch GD Neural Networks ka workhorse hai same scaling reason ke liye.
Convergence ke liye contraction factor ki magnitude <1 chahiye:
1−nα∑xi2<1⇒0<3α(14)<2⇒α<146=0.4286.
Iske upar, α≈0.4286 bina shrink hue oscillate karta hai, aur α>0.4286diverge karta hai — har step pehle se zyada overshoot karta hai. Safe rule: α<∑xi22n (general mein, α<2/λmax Hessian ka).
Recall Self-test cloze
Normal equation solution hai ::: w∗=(XTX)−1XTy
Gradient descent diverge karta hai jab α exceed kare ::: Hessian n1XTX ka 2/λmax
Ridge hamesha invertible rehta hai kyunki yeh add karta hai ::: nλI, jo har eigenvalue ko zero se upar lift karta hai
Optimum par residual hota hai ::: X ke har column ke saath orthogonal (XTr=0)