Why multiple features? Real-world phenomena depend on many variables. Single-feature regression ignores confounding factors. Multiple regression captures this complexity if relationships are roughly linear.
Writing y^=β0+β1x1+β2x2+⋯ for every prediction is tedious. With m training examples and n features, we have m equations. Matrix form compresses this elegantly.
Step 1: Represent data as matrices
For m examples, each with n features:
X=11⋮1x1(1)x1(2)⋮x1(m)x2(1)x2(2)⋱x2(m)⋯⋯⋮⋯xn(1)xn(2)xn(m),β=β0β1⋮βn,y=y(1)y(2)⋮y(m)
Why the leading1's column? That's the "feature" for β0. Makes the intercept just another coefficient in the dot product.
Step 2: Predictions as matrix multiplication
y^=Xβ
This single equation replaces m separate prediction formulas. Each row of X doted with β gives one prediction.
Goal: Find β that minimizes the mean squared error (MSE):
J(β)=m1∑i=1m(y(i)−y^(i))2
Why this step? We're finding where the cost function's slope is zero—the minimum. The second derivative (Hessian X⊤X) is positive definite, confirming it's a minimum, not maximum.
Normal Equation:O(n3) for matrix inversion + O(mn2) for X⊤X. Dominant cost: inversion.
When to use:
Small n (< 10,000 features): Normal Equation is fast, exact, no hyperparameters
Large n: Use gradient descent (O(kmn) for k iterations, k≪n)
Recall Explain to a 12-Year-Old
Imagine you're guessing how much candy someone will eat at a party. You notice three things matter: how hungry they are, how much they like sweets, and how many friends they're with.
Simple regression is like saying "I'll only look at hunger and ignore everything else." That's silly! Multiple regression is smarter: you make a formula that uses ALL three clues, giving each one a "weight" based on how important it is.
So your formula might be: Candy eaten = 5 + 2×(hunger) + 3×(sweetness love) + 1×(friends nearby). The computer finds the best weights by looking at past parties and figuring out which numbers make the fewest wrong guesses. It's like having a cheat sheet that uses multiple hints instead of just one!
Overfitting: More features → risk of fitting noise, need regularization
#flashcards/ai-ml
What is the matrix form of multiple linear regression predictions? :: y^=Xβ, where X is the design matrix (with leading 1's for intercept), β is the coefficient vector.
What is the Normal Equation for multiple linear regression?
β=(X⊤X)−1X⊤y. Derived by setting the gradient of MSE to zero.
Why do we add a column of 1's to the feature matrix X?
To represent the intercept term β0 as part of the matrix multiplication Xβ. The 1's act as the "feature" for the bias term.
When is X⊤X non-invertible?
When (1) m<n (fewer examples than features), or (2) perfect multicollinearity exists (one feature is an exact linear combination of others).
What are two alternatives when the Normal Equation fails?
(1) Use gradient descent instead (doesn't require inversion), (2) Add regularization like Ridge regression (X⊤X+λI).
What does a negative coefficient βi mean in multiple linear regression?
For every1-unit increase in feature xi, the predicted target y^ decreases by ∣βi∣ units, holding all other features constant.
What is multicollinearity?
When features are highly correlated with each other (e.g., x3≈2x1+x2). Causes unstable coefficient estimates and inflated variance.
Why is the Normal Equation O(n3) complexity?
Matrix inversion (X⊤X)−1 is O(n3) for an n×n matrix. This dominates the cost.
When should you use gradient descent over the Normal Equation?
When n is large (> 10,000 features). Gradient descent is O(kmn) for k iterations, avoiding the O(n3) inversion cost.
What does "holding other features constant" mean in coefficient interpretation?
The coefficient βi measures the isolated effect of xi on y^, as if all other features are frozen. Multiple regression disentangles each feature's contribution.
Dekho, yaha core idea bahut simple hai. Pehle humne ek single feature se prediction kiya tha, jaise sirf ghar ke size se price predict karna. Lekin real world mein cheezein itni simple nahi hoti — ghar ka price sirf size pe nahi, balki bedrooms, location, age, sab pe depend karta hai. Toh Multiple Linear Regression basically yahi karta hai: kai saare features ko ek saath use karke prediction banata hai, aur har feature ko ek weight (coefficient) deta hai jo batata hai ki wo feature kitna important hai. 2D mein jaise hum ek line fit karte the, ab high dimensions mein hum ek "hyperplane" fit kar rahe hain — concept wahi hai, bas dimensions zyada ho gaye.
Ab matrix notation kyun important hai? Socho tumhare paas hazaaron training examples hain, har ek ke liye alag-alag equation likhna practically impossible hai. Isliye hum saara data matrices mein pack kar dete hain — X matrix mein saare features, beta vector mein saare weights. Phir sirf ek chhota sa equation y = X·beta se saari predictions ek saath ho jaati hain. Wo jo leading 1's ka column dikhta hai na, wo intercept (β₀) ke liye hai, taaki bias bhi baaki coefficients ki tarah hi dot product mein aa jaaye. Ye trick calculations ko super clean aur fast bana deti hai, especially jab computer pe implement karna ho.
Aur sabse mast part hai Normal Equation. Hum error (MSE) ko minimize karna chahte hain, matlab prediction aur actual value ke beech ka gap kam se kam ho. Toh calculus use karke gradient nikaalte hain, usse zero pe set karte hain, aur seedha ek formula mil jaata hai jo optimal beta de deta hai — bina koi iterations ya guessing ke, one shot mein! Ye matter isliye karta hai kyunki ye foundation hai — machine learning ke bade models bhi isi linear algebra aur optimization ki soch pe khade hain. Ek baar ye intuition clear ho gayi toh aage neural networks tak sab samajhne mein aasaani hogi.