5.6.1 · D4 · HinglishMachine Learning (Aerospace Applications)

ExercisesLinear regression — normal equation, gradient descent derivation

2,642 words12 min read↑ Read in English

5.6.1 · D4 · Coding › Machine Learning (Aerospace Applications) › Linear regression — normal equation, gradient descent deriva

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.

Figure — Linear regression — normal equation, gradient descent derivation

Un do tools ko yaad karo jo hum baar baar use karte hain (parent note mein fully banaye gaye hain):

Related ideas jo tum saath mein open karna chahoge: Least Squares Estimation, Matrix Pseudoinverse, Convex Optimization, Feature Scaling, Regularization (Ridge, Lasso).


Level 1 — Recognition

Recall Solution L1.1

Bias column ke saath columns hain.

  • ka shape hai (rows points, columns featuresbias).
  • ka shape hai , isliye hai .
  • hai .
  • ek system solve karta hai isliye yeh hai.

Sanity check: mein unknowns ki sankhya () hamesha ke columns ki sankhya ke barabar hoti hai.

Recall Solution L1.2

(b). (a) absolute error hai — kinks ki wajah se 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.


Level 2 — Application

Recall Solution L2.1

ka top-left points count karta hai: . Off-diagonal hai . Bottom-right hai . : pehli entry ; doosri .

Recall Solution L2.2

Determinant: . Toh , . Line: .

Aankhon se check karo: par yeh predict karta hai (actual ), par predict karta hai (actual ) — errors balanced hain, jaise least squares demand karta hai.

Recall Solution L2.3

ke saath predictions sab hain, isliye error . Gradient :

  • pehli entry
  • doosri entry

Level 3 — Analysis

Recall Solution L3.1

Normal equation hai . Rearrange karo: Matlab (figure dekho): , ke columns se bane flat plane par ka shadow (projection) hai. Bacha hua us plane se seedha bahar point karta hai — possible mein se sabse chhota bacha hua. Koi bhi doosra zyada lamba residual chhod deta hai.

Figure — Linear regression — normal equation, gradient descent derivation
Recall Solution L3.2

Column 3 column 2, isliye columns linearly dependent hain. Tab singular hai (determinant ) aur 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 ka projection well-defined hai lekin coordinates jo usse reach karte hain unique nahi hain. Yeh multicollinearity hai. Fixes: ek redundant feature drop karo, ya Ridge add karo jo ko se replace karta hai ( ke liye hamesha invertible), ya Matrix Pseudoinverse use karo jo minimum-norm solution deta hai.

Recall Solution L3.3

ki second derivative (Hessian) hai . Kisi bhi nonzero direction ke liye, , aur yeh hota hai jab columns independent hon. Ek matrix jisme sab positive curvatures hon woh positive definite hai, isliye 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.


Level 4 — Synthesis

Recall Solution L4.1

, . , det . : ; . Toh . (ii) Kyunki strictly convex hai (L3.3) aur invertible hai, gradient descent kaafi chhote ke saath same unique minimum 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 se set hoti hai. vs 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 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 ke liye yeh convenient hai.

Recall Solution L4.3

Gradient lo aur zero set karo. Extra term contribute karta hai: se multiply karo aur group karo: Kyunki ke eigenvalues hain, () add karne se har eigenvalue 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.


Level 5 — Mastery

Recall Solution L5.1

Normal equation out hai: () form karna aur invert karna operations plus memory entries cost karta hai — infeasible hai, aur yeh live stream ingest nahi kar sakta. Full batch GD har step mein 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 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.

Recall Solution L5.2

, . (det ). : , . (ii) Predictions : par dete hain. Residuals . . Cost . (iii) : pehli entry ; doosri . ✓ Residual dono columns ke saath orthogonal hai, projection picture confirm ho gayi.

Recall Solution L5.3

Convergence ke liye contraction factor ki magnitude chahiye: Iske upar, bina shrink hue oscillate karta hai, aur diverge karta hai — har step pehle se zyada overshoot karta hai. Safe rule: (general mein, Hessian ka).

Recall Self-test cloze

Normal equation solution hai ::: Gradient descent diverge karta hai jab exceed kare ::: Hessian ka Ridge hamesha invertible rehta hai kyunki yeh add karta hai ::: , jo har eigenvalue ko zero se upar lift karta hai Optimum par residual hota hai ::: ke har column ke saath orthogonal ()