Simple Linear Regression (One Variable)
🔹 Definition
Simple Linear Regression (SLR) is a supervised learning method used to model the relationship between:
-
One independent variable (input)
-
One dependent variable (output)
👉 It assumes a linear relationship between them
🔹 Problem Formulation
Given dataset:
👉 Goal:
Learn a function:
🔹Model Representation (Hypothesis)
The model is a straight line:
Where:
-
→ intercept
-
→ slope
-
→ input
-
→ predicted output
👉 This represents the best-fit line through the data
🔹 Interpretation of Parameters
📌 Intercept ()
-
Value of when
📌 Slope ()
-
Change in for a unit change in
👉 Example:
If slope = 2 → increasing by 1 increases by 2
🔹Key Idea: Best-Fit Line
👉 The regression line is chosen such that:
-
It minimizes the error between actual and predicted values
-
Error = vertical distance from data point to line
👉 This is called residual
🔹 Loss Function (Important)
Most commonly used:
👉 This is Mean Squared Error (MSE)
👉 Goal:
👉 The best-fit line minimizes squared errors
🔹 Solution (Closed Form)
🔹 Problem Setup
Given data:
Model:
👉 Goal: Find that best fit the data.
🔹 Define Loss Function (Least Squares)
👉 We minimize this error.
🔹 Take Partial Derivatives
We compute:
🔹 Derivative w.r.t.β0
Set to zero:
Simplify:
🔹 Derivative w.r.t.β1
Set to zero:
🔹 Solve the Two Equations
We now have:
Equation (1):
Equation (2):
🔹 Use Mean Values
Let:
From Equation (1):
🔹Substitute into Equation (2)
Expand:
Rearrange:
🔹 Final Simplification
Using:
Identity 1
Identity 2
We get:
From optimization, we get:
Key Insight
An alternate simplification which helps in simple computation
Alternate Formula (Using Raw Sums)
Alternate Formulas for Simple Linear Regression - Summary
🔹 1. Using Mean Values (Most Important)
Slope
Intercept
🔹 2. Equivalent Statistical Form
This is a very elegant form:
🔹 3. Alternate Formula (Using Raw Sums)
look at the simplification here
🔹 When to Use Which?
| Method | When to Use |
|---|
| Mean form | Easier for understanding |
| Raw sum form | Faster in exams |
| Covariance form | Conceptual questions |
🔹 Intuition
👉 Simple linear regression tries to:
-
Fit a line through data points
-
Capture trend between variables
Assumptions of Simple Linear Regression
- Linearity
-
Relationship between and is linear
-
Independence
-
Observations are independent
-
Constant variance (Homoscedasticity)
-
Error variance is constant
-
Normality of errors
-
Errors are normally distributed
🔹Example
📌 Salary Prediction
-
Input: Years of experience ()
-
Output: Salary ()
Model:
👉 Used widely in real-world ML tasks
🔹 Steps in Applying SLR
-
Collect data
-
Plot data (scatter plot)
-
Choose linear model
-
Define loss function
-
Estimate parameters
-
Evaluate model
🔹 Advantages
-
Simple and interpretable
-
Fast computation
-
Works well for linear relationships
🔹Limitations
-
Cannot model non-linear patterns
-
Sensitive to outliers
-
Assumes linearity
📝 Summary
Comments
Post a Comment