Multiple Linear Regression: A Solved Numerical Example

Scenario: Restaurant Revenue Prediction

The Objective: Predict a restaurant's weekly revenue (£'s) based on seating capacity and average customer rating.

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.80
1253.20
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.803.20
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.500.67-20.83
0.670.03-0.44
-20.83-0.449.72
Multiply Inverse by XTX^T
(XTX)1XT(X^T \cdot X)^{-1} \cdot X^T
-5.502.004.50
-0.100.13-0.03
2.50-1.67-0.83

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.00
0.27
1.67

Intercept (b0b_0) : -2.00

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

Weight for X2X_{2} (b2b_{2}) : 1.67

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.0000 + (0.2667 * 45) + (1.6667 * 4.1)

Y = 16.83

Final Takeaway

Based on the interactions between all selected features, the model predicts an estimated result of 16.83.