Linear regression finds the best-fit line (or hyperplane) through data by minimizing the sum of squared errors. In aerospace, this powers trajectory prediction, sensor calibration, and control system parameter identification.
Why this step? Converting the norm into a dot product so we can apply matrix derivative rules.
Expand:
=2n1(yTy−yTXw−wTXTy+wTXTXw)
Since yTXw is a scalar, it equals its transpose: yTXw=wTXTy.
=2n1(yTy−2wTXTy+wTXTXw)
Step 2: Take the derivative with respect to w and set to zero.
∂w∂J=2n1(−2XTy+2XTXw)=n1(XTXw−XTy)
Why this step? At the minimum, the gradient is zero (no slope in any direction). We use:
∂w∂(aTw)=a
∂w∂(wTAw)=2Aw (for symmetric A)
Set gradient to zero:
XTXw=XTy
Step 3: Solve for w.
Geometric intuition: Xw∗ is the orthogonal projection of y onto the column space of X. The error vector y−Xw∗ is perpendicular to all columns of X, hence XT(y−Xw∗)=0.
Continue until convergence → approaches [0.667,1.5]T.
Why gradient descent? When d=10,000 (e.g., image features for spacecraft pose estimation), computing the inverse is infeasible, but each gradient step is fast.
Imagine you're trying to draw the best straight line through a bunch of dots on graph paper. "Best" means the line is as close to all the dots as possible. You measure "closeness" by drawing vertical lines from each dot to your line and adding up the lengths of those lines (squared so big mistakes count more).
The normal equation is like using a ruler and protractor to calculate the exact perfect angle and position in one go. You do some matrix math and boom—done.
Gradient descent is like starting with a random line, then slowly tilting and sliding it. You look at where the dots are, figure out which way makes things worse, and move the opposite way. You repeat this over and over, each time making a small adjustment, until the line can't get any better. It takes longer but works even if the "ruler method" is too complicated (like if you have a million dots).
Aerospace engineers use this to predict things like how much fuel a plane will burn at different speeds—plot speed vs. fuel, find the best line, then use it to plan flights.
Normal equation: w∗=(XTX)−1XTy (one-shot, O(d3), requires invertibility)
Gradient descent: wt+1=wt−α∇J (iterative, O(nd) per step, scales to large d)
Derived from minimizing 2n1∥y−Xw∥2 by setting ∇J=0 or stepping against ∇J
Key tradeoffs: exact vs. iterative, memory vs. computation, batch vs. stochastic
#flashcards/coding
What is the normal equation for linear regression? :: w∗=(XTX)−1XTy
Derive the normal equation from J(w)=2n1∥y−Xw∥2 :: Expand to 2n1(yTy−2wTXTy+wTXTXw), take derivative ∂w∂J=n1(XTXw−XTy), set to zero: XTXw=XTy, solve: w∗=(XTX)−1XTy
What is the gradient descent update rule for linear regression?
wt+1=wt−nαXT(Xwt−y)
What is the gradient of MSE cost J(w)=2n1∥y−Xw∥2?
∇wJ=n1XT(Xw−y)
When should you use normal equation vs. gradient descent?
Normal equation: small d (<10K features), need exact solution, invertible XTX. Gradient descent: large d, online learning, singular matrix issues.
What is the time complexity of computing the normal equation?
O(d3) for matrix inversion plus O(nd2) for XTX, dominated by O(d3)
What happens if learning rate α is too large in gradient descent?
Cost oscillates or diverges (overshoots minimum at each step)
What is stochastic gradient descent (SGD)?
Update weights using one sample at a time: wt+1=wt−α(xiTwt−yi)xi
Dekho, linear regression ka basic idea ye hai ki hum apne data points ke through ek aisi best-fit line ya hyperplane khinchna chahte hain jo predictions de sake. Jaise aerospace mein agar altitude se fuel burn rate predict karna ho, toh humein aisi line chahiye jiska total error sabse kam ho. Ab error ko hum square karte hain — kyunki agar positive aur negative errors ko aise hi jodenge toh wo ek dusre ko cancel kar denge, aur squaring se calculus bhi smoothly kaam karta hai (derivatives har jagah exist karti hain). Isi squared error ke sum ko minimize karna hi humara asli goal hai, aur isko hum cost function J(w) kehte hain.
Ab is minimum ko dhoondhne ka ek shaandaar tareeka hai — Normal Equation. Iska logic simple hai: jahan cost function minimum hoti hai, wahan uski gradient (slope) zero hoti hai. Toh hum J(w) ko w ke respect mein differentiate karke zero ke barabar rakhte hain, aur thoda matrix algebra karke seedha ek closed-form formula mil jaata hai: w* = (XᵀX)⁻¹Xᵀy. Iska matlab hum bina kisi iteration ke, ek hi step mein exact answer nikaal lete hain. Geometrically socho toh Xw* actually y ka orthogonal projection hai X ke column space par — yaani error vector baaki sabhi columns ke perpendicular ho jaata hai, jo minimum error ki guarantee deta hai.
Ye cheez isliye important hai kyunki aerospace jaise fields mein chhoti si prediction error bhi lambe flights mein compound hoti jaati hai, isliye humein globally best coefficients chahiye — approximate nahi. Normal equation fast aur exact hai jab features kam hain, lekin dhyaan rakho: agar features bahut zyada ho jaayein toh (XᵀX)⁻¹ nikaalna O(d³) ke saath mehenga pad jaata hai, aur multicollinearity ho toh matrix singular ban jaata hai. Isiliye aage chalke gradient descent jaisi iterative methods kaam aati hain — par unki foundation samajhne ke liye ye normal equation waali intuition pehle clear honi zaroori hai.