Fitting a Multiple Linear Regression Model Using the Normal Equation
Problem Setup
Scenario:Estimate a restaurant's weekly revenue based on its seating capacity and average customer rating.
Given:Three historical restaurant records containing seating capacity, average rating, and the corresponding weekly revenue in hundreds of pounds.
Task:Use multiple linear regression to model weekly revenue from both seating capacity and average rating, then estimate the weekly revenue for a restaurant with 45 seats and an average rating of 4.1.
Need a quick refresher? Review Multiple Linear theory
Restaurant Capacity, Rating & Revenue
Each row contains a restaurant's seating capacity, average rating, and weekly revenue in hundreds of pounds. These observations are used to fit a regression model with two input 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-by-Step Solution
Step 1: Extract X and Y Matrices
Step 2: Calculate Transpose ()
Step 3: Multiply ()
Step 4: Find Inverse
Step 5: Multiply Inverse by
Step 6: Calculate Regression Coefficients
Intercept () : -2
Weight for () : 0.267
Weight for () : 1.667
Step 7: Calculate Target Prediction
Line:
* Note: Intermediate coefficients are displayed in rounded form. The final prediction is calculated using full precision.
Final Answer
Prediction:16.833 hundred GBP
Interpretation:The model estimates weekly revenue using both seating capacity and average rating. This estimate is based on only three historical records, so it should not be treated as a reliable forecast of actual revenue.
Exam Takeaway
- Keep coefficient order consistent: Each coefficient corresponds to a specific column of the design matrix. The first coefficient belongs to the intercept column, and the remaining coefficients follow the order of the input features. Mixing this order produces incorrect predictions.
- Check when the normal equation is applicable: The inverse-based formula requires to be invertible. If the feature columns are linearly dependent, the inverse does not exist, and another method such as the pseudoinverse is needed.
- A perfect fit does not guarantee reliable predictions: This example has three observations and three regression coefficients, allowing an exact fit because the design matrix is invertible. However, the model has no residual degrees of freedom, so its ability to generalize to unseen data cannot be established from these records alone.