In the previous article, we learned about Simple Linear Regression, where a model predicts a target variable using a single input feature.
However, real-world problems are rarely that simple.
Consider predicting house prices.
Would house price depend only on area?
Probably not.
Factors such as:
- Area
- Number of Bedrooms
- Location
- Age of Property
- Distance from City Center
- Nearby Schools
all influence the final price.
Similarly:
Employee salary may depend on:
- Experience
- Education
- Skills
- Certifications
- Company Size
To handle such situations, we use Multiple Linear Regression.
Multiple Linear Regression extends Simple Linear Regression by using multiple input features to predict a target variable.
It is one of the most widely used Machine Learning algorithms and forms the foundation of many advanced predictive models.
What is Multiple Linear Regression?
Multiple Linear Regression is a supervised Machine Learning algorithm that models the relationship between:
- Multiple Independent Variables (Features)
- One Dependent Variable (Target)
Example:
| Experience | Education | Skills Score | Salary |
|---|---|---|---|
| 2 | Bachelor's | 70 | 5 LPA |
| 5 | Master's | 85 | 10 LPA |
| 8 | Master's | 95 | 16 LPA |
Goal:
Predict Salary using multiple features.
Why Do We Need Multiple Features?
Suppose we want to predict house prices.
Dataset:
| Area | Price |
|---|---|
| 1000 | 50 |
| 1500 | 75 |
Simple Linear Regression uses only Area.
But two houses can have the same area and very different prices.
Example:
| Area | Bedrooms | Location | Price |
|---|---|---|---|
| 1500 | 2 | Rural | 60 |
| 1500 | 4 | City | 90 |
Area alone cannot explain the difference.
Multiple features are needed.
From Simple to Multiple Regression
Simple Linear Regression:
Only one feature is used.
Multiple Linear Regression expands this idea.
Multiple Linear Regression Equation
Where:
- = Predicted value
- = Intercept
- = Coefficients
- = Features
Understanding the Equation
Suppose:
For:
Experience = 4
SkillScore = 80
Prediction:
The model combines information from multiple features.
Understanding Features
Features are the input variables used to make predictions.
Example:
House Price Dataset
| Feature |
|---|
| Area |
| Bedrooms |
| Bathrooms |
| Age |
| Location Score |
Target:
Price
Each feature contributes differently.
Understanding Coefficients
Coefficients represent the impact of a feature on the target variable.
Example:
Interpretation:
- Every additional square foot increases price by 0.05 units.
- Every additional bedroom increases price by 5 units.
Positive Coefficients
Example:
Higher experience increases salary.
Positive coefficient:
Negative Coefficients
Example:
As property age increases, price decreases.
Negative coefficient:
Intercept in Multiple Regression
The intercept represents:
Predicted value when all features equal zero.
Example:
If:
Area = 0
Then:
This value is the intercept.
Visualizing Multiple Regression
Simple Linear Regression:
Straight line in 2D.
Multiple Linear Regression:
Plane or hyperplane in higher dimensions.
Example:
Two Features:
Salary
^
/
/
/
/
--------/-------->
Experience
Skills
The model finds the best-fitting plane.
How Does the Model Learn?
The model:
- Takes historical data
- Tries different coefficients
- Makes predictions
- Calculates errors
- Adjusts coefficients
- Finds the best combination
The objective is:
Minimize prediction error.
Example Dataset
| Experience | Skills | Salary |
|---|---|---|
| 1 | 50 | 3 |
| 3 | 70 | 7 |
| 5 | 85 | 12 |
The model learns:
Predictions Using Multiple Features
Suppose:
| Feature | Value |
|---|---|
| Experience | 4 |
| Skills | 80 |
The model combines both features to estimate salary.
Unlike Simple Linear Regression, predictions now depend on multiple variables simultaneously.
Why Multiple Regression Performs Better
Real-world outcomes usually depend on several factors.
Example:
Predicting Student Marks
Features:
- Study Hours
- Attendance
- Previous Grades
- Sleep Hours
Using only Study Hours would ignore valuable information.
Multiple Linear Regression utilizes all available information.
Matrix Representation
For large datasets, the equation is written using matrices.
Where:
- = Target values
- = Feature matrix
- = Coefficient vector
Matrix notation simplifies calculations.
Training Multiple Linear Regression in Python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
Making Predictions
predictions = model.predict(X_test)
Viewing Coefficients
print(model.coef_)
Example Output:
[1.5, 0.8, -0.3]
Each value corresponds to a feature.
Viewing Intercept
print(model.intercept_)
Example:
2.4
Example: House Price Prediction
Features:
- Area
- Bedrooms
- Age
Model:
Interpretation:
- Larger houses cost more.
- More bedrooms increase value.
- Older houses decrease value.
Feature Importance Through Coefficients
Large coefficient magnitude often indicates stronger influence.
Example:
| Feature | Coefficient |
|---|---|
| Area | 0.05 |
| Bedrooms | 8 |
| Age | -1 |
Bedrooms have the strongest effect.
However:
Feature scaling may affect interpretation.
Advantages of Multiple Linear Regression
- Easy to understand
- Fast training
- Highly interpretable
- Handles multiple features
- Strong baseline model
Limitations of Multiple Linear Regression
- Assumes linear relationships
- Sensitive to outliers
- Struggles with complex patterns
- Requires careful feature selection
Multiple Linear Regression vs Simple Linear Regression
| Simple Linear Regression | Multiple Linear Regression |
|---|---|
| One Feature | Multiple Features |
| Straight Line | Plane/Hyperplane |
| Simpler | More Powerful |
| Limited Information | Uses More Information |
Real-World Applications
House Price Prediction
Features:
- Area
- Bedrooms
- Location
Target:
Price
Salary Prediction
Features:
- Experience
- Education
- Skills
Target:
Salary
Sales Forecasting
Features:
- Advertising Budget
- Product Price
- Season
Target:
Sales
Loan Risk Prediction
Features:
- Income
- Credit Score
- Existing Debt
Target:
Risk Score
Common Mistakes
Using Highly Correlated Features
Example:
- Monthly Income
- Annual Income
Both provide nearly identical information.
This creates:
Multicollinearity
which can destabilize coefficients.
Ignoring Feature Scaling
Features with different scales may affect interpretation.
Assuming Correlation Means Causation
A feature may correlate with the target without causing it.
Always use domain knowledge.
Best Practices
- Select meaningful features
- Remove redundant variables
- Handle outliers
- Check assumptions
- Evaluate model performance
- Interpret coefficients carefully
Multiple Linear Regression Workflow
A typical workflow is:
- Collect data
- Select features
- Split data into train and test sets
- Train the model
- Learn coefficients
- Make predictions
- Measure errors
- Improve features if necessary
Why Multiple Linear Regression is Important
Most real-world Machine Learning problems involve multiple factors influencing the target variable. Multiple Linear Regression provides a simple yet powerful framework for modeling these relationships.
It introduces important concepts such as coefficients, feature contributions, multivariate prediction, and model interpretation. Understanding Multiple Linear Regression is essential because many advanced Machine Learning algorithms build upon the same principles of learning relationships between multiple features and a target variable.
In the next article, we will learn about the Cost Function, which explains how regression models measure prediction errors and determine whether one model is better than another.