Linear regression — normal equation, gradient descent derivation
5.6.1· Coding › Machine Learning (Aerospace Applications)
Linear regression best-fit line (ya hyperplane) dhundhta hai data ke through, sum of squared errors minimize karke. Aerospace mein, yeh trajectory prediction, sensor calibration, aur control system parameter identification ke liye use hota hai.
Why Linear Regression?
Problem Setup
Vectorized form: Data ko matrix mein stack karo (har row hai), targets . Bias ko mein absorb karo mein 1s ka column add karke. Tab:
Method 1: Normal Equation (Closed-Form Solution)
Derivation from First Principles
Goal: dhundho jo minimize kare, calculus use karke.
Step 1: Cost function expand karo.
Yeh step kyun? Norm ko dot product mein convert karna taaki matrix derivative rules apply kar sakein.
Expand karo:
Kyunki ek scalar hai, yeh apne transpose ke barabar hai: .
Step 2: ke respect mein derivative lo aur zero set karo.
Yeh step kyun? Minimum par, gradient zero hota hai (kisi bhi direction mein slope nahi). Hum use karte hain:
- (symmetric ke liye)
Gradient ko zero set karo:
Step 3: ke liye solve karo.
Geometric intuition: , ka orthogonal projection hai ke column space par. Error vector , ke sabhi columns ke perpendicular hai, isliye .

When to Use Normal Equation
Pros:
- One-shot solution (koi iteration nahi)
- Exact (numerical precision tak)
Cons:
- compute karna hai jahan feature count hai
- Fail hota hai agar singular ho (multicollinearity)
- ke liye impractical (aerospace sensor fusion mein common)
Method 2: Gradient Descent (Iterative Optimization)
Derivation from First Principles
Core idea: Ek random se shuru karo, baar baar us direction mein step lo jo ko sabse tezi se decrease kare (negative gradient).
Step 1: ke respect mein ka gradient compute karo.
Pehle se:
Yeh form kyun? error vector hai (predictions minus actuals). se multiply karna har feature ko weight deta hai uske hisaab se ki usne error mein kitna contribute kiya.
Step 2: Update rule.
Yeh step kyun? Hum gradient ke opposite direction mein move karte hain (downhill). control karta hai step kitna bada ho — bahut bada ho toh overshoot, bahut chhota ho toh convergence slow hogi.
Step 3: Convergence tak repeat karo.
Convergence criteria:
- (gradient almost zero)
- (cost decrease karna band ho jaaye)
- Maximum iterations reach ho jaayein
Variants
Worked Examples
Bias column add karo: ,
,
Yeh step kyun? Matrix multiplication: . ki pehli entry hai ; doosri hai .
Solve karo :
Inverse:
Result: , . Toh .
Yeh kyun matter karta hai: Aerospace sensor calibration mein aksar reference measurements par lines fit karni padti hain.
Iteration 0:
- Predictions:
- Error:
- Gradient:
- Yeh step kyun? ka shape hai, error hai, result hai. Doosra component: .
- Update:
Iteration 1:
- Error:
- Gradient:
- Update:
Convergence tak continue karo → ke paas pahunch jaayega.
Gradient descent kyun? Jab ho (jaise spacecraft pose estimation ke liye image features), inverse compute karna infeasible hai, lekin har gradient step fast hota hai.
Common Mistakes
Active Recall
Recall Ek 12-Saal Ke Bacche Ko Explain Karo
Socho tum graph paper par dots ke through sabse achhi straight line draw karne ki koshish kar rahe ho. "Best" matlab line sabse zyada dots ke paas ho. "Closeness" measure karte ho har dot se line tak vertical lines khinchke aur un lines ki lengths add karke (squared isliye taaki badi mistakes zyada count karein).
Normal equation aisa hai jaise ek baar mein ruler aur protractor se exact perfect angle aur position calculate karo. Kuch matrix math karo aur ho gaya — ekdum done.
Gradient descent aisa hai jaise ek random line se shuru karo, phir dheere dheere use tilt aur slide karo. Dekho dots kahan hain, pata karo kaun sa direction cheezein worse banata hai, aur opposite direction mein move karo. Yeh baar baar repeat karo, har baar chhota sa adjustment karte hue, jab tak line aur better na ho sake. Zyada time lagta hai lekin kaam karta hai jab "ruler method" bahut complicated ho (jaise agar ek million dots hों).
Aerospace engineers isko use karte hain yeh predict karne ke liye ki plane alag alag speeds par kitna fuel burn karega — speed vs. fuel plot karo, best line dhundho, phir flights plan karne ke liye use karo.
Gradient Descent = "ITERATIVE steps ALPHA tuned"
- Iterative process
- Tiny steps (learning rate )
- Efficient for high dimensions
Connections
- Least Squares Estimation — same MSE criterion, weighted/nonlinear cases ke liye generalized
- Matrix Pseudoinverse — singular handle karta hai
- Convex Optimization — kyun gradient descent converge karta hai (MSE convex hai)
- Feature Scaling — GD convergence ke liye zaroori
- Regularization (Ridge, Lasso) — overfitting rokne ke liye penalty term add karta hai
- Kalman Filtering — dynamic systems ke liye recursive least squares (spacecraft tracking)
- Neural Networks — gradient descent backpropagation mein generalize hota hai
Summary
- Normal equation: (one-shot, , invertibility chahiye)
- Gradient descent: (iterative, per step, large ke liye scale karta hai)
- minimize karne se derive hota hai set karke ya ke against step lekar
- Key tradeoffs: exact vs. iterative, memory vs. computation, batch vs. stochastic
#flashcards/coding
Linear regression ke liye normal equation kya hai? ::
se normal equation derive karo :: Expand karo mein, derivative lo , zero set karo: , solve karo: