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 βj\beta_j represents the change in y^\hat{y} for a one-unit increase in xjx_j, 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 PointSeating_CapacityAvg_RatingWeekly_Revenue_hundreds
P135414
P2403.815
P3253.210
Target454.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 b0b_0

Formula: X=[1x11x121x21x22],Y=[y1y2]X = \begin{bmatrix} 1 & x_{11} & x_{12} \\ 1 & x_{21} & x_{22} \\ \dots \end{bmatrix}, \quad Y = \begin{bmatrix} y_1 \\ y_2 \\ \dots \end{bmatrix}
Matrix XX (with 1s)
1354
1403.8
1253.2
Matrix YY
14
15
10

Step 3: Calculate X-Transpose and Multiply

We flip the rows and columns of Matrix XX to create its Transpose (XTX^T). Then, we multiply XTX^T by the original XX matrix to create a square matrix.

Calculate Transpose (XTX^T)
XTX^T
111
354025
43.83.2
Multiply (XTXX^T \cdot X)
(XTX)(X^T \cdot X)
310011
1003450372
1137240.68

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!

Find Inverse (XTX)1(X^T \cdot X)^{-1}
(XTX)1(X^T \cdot X)^{-1}
54.50.667-20.833
0.6670.029-0.444
-20.833-0.4449.722
Multiply Inverse by XTX^T
(XTX)1XT(X^T \cdot X)^{-1} \cdot X^T
-5.524.5
-0.10.133-0.033
2.5-1.667-0.833

Step 5: Solve for B (Weights & Intercept)

Finally, we multiply our accumulated matrix by the original Matrix YY. This yields the Beta Matrix (BB), which contains our intercept (b0b_0) and the optimal weights (b1,b2,dotsb_1, b_2, dots) for our features.

Formula: B=[(XTX)1XT]YB = [(X^T \cdot X)^{-1} \cdot X^T] \cdot Y
Matrix BB
-2
0.267
1.667

Intercept (b0b_0) : -2

Weight for X1X_{1} (b1b_{1}) : 0.267

Weight for X2X_{2} (b2b_{2}) : 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!

Formula: Y=b0+b1X1+b2X2++bnXnY = b_0 + b_1X_1 + b_2X_2 + \dots + b_nX_n
Calculating the Target 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 b0b_0.