Linear Regression
The first step towards Machine Learning β predicting numbers using data π
1οΈβ£ What is Linear Regression?
Linear Regression is a technique used to predict a number using past data.
π It finds a straight-line relationship between:
- Input (X) β what we know
- Output (Y) β what we want to predict
Example: If we know hours studied, can we predict marks? β‘οΈ Yes, using Linear Regression.
2οΈβ£ Real-World Examples (Easy to Remember)
House Price
X = Size (sq.ft)
Y = Price
Bigger house β higher price
Cab Fare
X = Distance
Y = Fare
More distance β more cost
Exam Marks
X = Study Hours
Y = Marks
More study β better marks
3οΈβ£ How does Linear Regression work? (Intuition)
Imagine you plotted many points on a graph π (each point is one student / house / trip).
Now your task is to draw one straight line such that:
- The line is close to most points
- The total mistake is minimum
That line is called the Best Fit Line.
4οΈβ£ Visual Explanation
π΅ Blue line = Prediction
π΄ Red lines = Errors (difference between actual & predicted)
5οΈβ£ Formula (Donβt panic π)
Once intuition is clear, math becomes easy.
Linear Equation
y = m x + c
(Also written as y = Ξ²β + Ξ²βx)
- m (Slope): How much Y changes when X increases by 1
- c (Intercept): Starting value when X = 0
Interview Checkpoint π―
What is Best Fit Line?
It is the line that gives the least total error between predicted and actual values.
What is R-Squared?
It tells how good the model is.
0 β very bad
1 β perfect prediction
Can Linear Regression handle curves?
No β It only works for straight-line relationships.