CHAPTER 07
Intermediate
Multiple Linear Regression
Updated: May 16, 2026
6 min read
# CHAPTER 7
Multiple Linear Regression
1. Introduction
Simple Linear Regression (using one feature) is great for learning, but terrible for reality. If you predict a house's price using *only* its Square Footage, you will be shockingly inaccurate because you ignored the number of Bedrooms, the Age of the house, and the Distance to the city center. Multiple Linear Regression solves this by allowing the algorithm to analyze dozens, hundreds, or even thousands of features simultaneously to make a highly accurate prediction.2. Learning Objectives
By the end of this chapter, you will be able to:- Understand the math behind Multiple Linear Regression.
- Train a model using multiple input features.
- Interpret multiple Coefficients to determine Feature Importance.
- Build a House Price prediction model.
3. The Math: Expanding the Equation
In Simple Linear Regression, the formula was a simple 2D line: $y = (m \times x) + b$. In Multiple Linear Regression, we simply add more variables! If we have 3 features (Size, Bedrooms, Age), the model creates a 4D hyper-plane: $$y = (m1 \times X1) + (m2 \times X2) + (m3 \times X3) + b$$- $m1$ (Coefficient 1): The weight assigned to Size.
- $m2$ (Coefficient 2): The weight assigned to Bedrooms.
- $m_3$ (Coefficient 3): The weight assigned to Age.
4. Mini Project: House Price Prediction
Let's build a model predicting house prices using 3 features: Size (sqft), Bedrooms, and Age (years).
python
5. Feature Importance (Interpreting Coefficients)
The most powerful aspect of Linear Regression is that it is a "White Box" model. We can look inside and see exactly *why* it made its decision by looking at the generated Coefficients ($m$).
python
Interpretation: The algorithm mathematically proved that:
- Every extra square foot adds $150 to the value.
- Every extra bedroom adds $25,000 to the value.
- Every year the house gets older, it *loses* $5,000 in value (Negative Correlation!).
6. The Problem of Scale
If you look at the coefficients above, Bedrooms is $25,000 and Size is only $150. Does this mean Bedrooms are the most important feature? No! Bedrooms only go up by 1 or 2. Size goes up by 1000s. Because the raw data is on entirely different scales, the raw coefficients can be misleading. To truly compare feature importance, we must "Standardize" the data first (which we cover deeply in Chapter 9).7. Why Visualizing Multiple Regression is Hard
You can easily visualize Simple Linear Regression on a 2D piece of paper (X and Y axis). If you have two features (Size, Bedrooms), the graph becomes a 3D cube, and the line becomes a flat "Plane". If you have three features, it becomes a 4D hyper-cube, which human brains cannot visualize. Therefore, we rely heavily on mathematical error metrics (like R-Squared) rather than visual graphs to judge accuracy in multiple regression.8. Common Mistakes
- The Dummy Variable Trap: If you include categorical data (e.g., "City: NY, LA, SF"), you must convert them to 1s and 0s (One-Hot Encoding). If you don't drop one of the encoded columns, it creates perfect Multicollinearity, crashing the mathematical equation.
- Throwing Garbage Data In: Adding 100 random, irrelevant columns (like the homeowner's favorite color) to a multiple regression model will not make it smarter. It will confuse the algorithm and cause Overfitting.
9. Best Practices
- Feature Selection: More features do not equal a better model. Only include features that logically have a correlation to the target.
10. Exercises
- 1. In the equation $y = (m1 \times X1) + (m2 \times X2) + b$, what does $X2$ represent in our housing example?
- 2. Why would the coefficient ($m$) for the "Age" of a car be a negative number when predicting the car's price?
11. MCQ Quiz with Answers
Question 1
What is the primary difference between Simple Linear Regression and Multiple Linear Regression?
Question 2
If model.coef[2] (representing Age of a house) equals -4000, what does this mathematically signify to the business?
12. Interview Questions
- Q: Explain why comparing the raw, unscaled coefficients in a Multiple Linear Regression model is not a reliable way to determine feature importance.
- Q: How does a Multiple Linear Regression model differ geometrically from a Simple Linear Regression model?