Multiple Linear Regression: A Solved Numerical Example
Scenario: Restaurant Revenue Prediction
The Objective: Predict a restaurant's weekly revenue by using matrix algebra to calculate exactly how multiple features simultaneously impact the bottom line.
Core Mechanics▼
- Beyond the 2D Line: While simple regression fits a line, multiple regression fits a hyperplane across all your features. The core logic remains: it’s just a weighted sum of all your inputs plus a baseline intercept.
- The "Holding Constant" Rule: This is crucial for exams! Each coefficient represents the change in for a one-unit increase in , assuming all other features remain fixed.
- Beware Multicollinearity: If your input features are strongly correlated with each other, the model gets "confused." The predictions might still be accurate, but your coefficients become unstable, making it impossible to interpret which feature is actually driving the result.
- Dimensionality Expansion: Just because you can’t visualize a 5-dimensional hyperplane doesn’t mean the math changes! The model still finds the optimal "fit" by minimizing errors across every dimension simultaneously, exactly like it did in 2D.
Step 1: The Historical Data & Target Point
When we have more than one independent variable (feature), we use Multiple Linear Regression to find a hyper-plane of best fit. We are trying to predict the Weekly_Revenue_hundreds using the given features.
| Data Point | Seating_Capacity | Avg_Rating | Weekly_Revenue_hundreds |
|---|---|---|---|
| P1 | 35 | 4 | 14 |
| P2 | 40 | 3.8 | 15 |
| P3 | 25 | 3.2 | 10 |
| Target | 45 | 4.1 | ? |
Step 2: Extract X and Y Matrices
First, we convert our tabular data into matrices. Notice how we add a column of 1s to the very beginning of the X Matrix. This acts as a placeholder for our Y-intercept
Step 3: Calculate X-Transpose and Multiply
We flip the rows and columns of Matrix to create its Transpose (). Then, we multiply by the original matrix to create a square matrix.
Step 4: Find Inverse and Multiply
Because there is no "division" in matrix math, we find the Inverse of our square matrix. Multiplying by an inverse is the mathematical equivalent of dividing!
Step 5: Solve for B (Weights & Intercept)
Finally, we multiply our accumulated matrix by the original Matrix . This yields the Beta Matrix (), which contains our intercept () and the optimal weights () for our features.
Intercept () : -2
Weight for () : 0.267
Weight for () : 1.667
Step 6: Final Equation & Prediction
We extract those weights and build our Multiple Linear Regression equation. Then we plug in our new Target Point to calculate the final prediction!
Line: Y = -2 + (0.267 * 45) + (1.667 * 4.1)
Y = 16.833
Final Takeaway
Look closely at Step 2: we deliberately injected a column of 1s into the beginning of the X Matrix! Forgetting this step is the most common exam mistake, because without those 1s acting as a mathematical placeholder, Step 5 would be completely unable to calculate the baseline Y-intercept .