Linear regression
Supervised · Regression Linear regression predicts a number by finding the straight line that best fits past data. The line is a simple formula, such as price = base amount + (rate × size). "Best fit" means the line where the total error between the line and the real points is as small as possible.
Everyday analogy
An auto-rickshaw fare: a fixed base fare plus a rate per kilometre. Linear regression looks at many past trips and works out the base fare and the per-km rate on its own.
Example
Used for: house and flat prices, sales forecasts from advertising spend, estimating delivery time, predicting electricity use.
The best-fit line
How it works, step by step
- Collect past examples: each flat's size and its actual price.
- Draw a straight line through the points.
- Measure how far each point is from the line. These gaps are the errors.
- Tilt and shift the line until the total of the squared errors is the smallest possible. This is called least squares.
- Use the final line to predict the price of any new flat from its size.
Worked example
Past flats: 600 sq ft sold for ₹30 lakh, 800 sq ft for ₹40 lakh, 1,000 sq ft for ₹50 lakh. The best line is price = ₹5,000 × size.
New flat of 900 sq ft → 900 × ₹5,000 = ₹45 lakh. Real data is messier, so the line is the best compromise through all the points. With more features (location, floor, age) it becomes multiple linear regression.
✓ Good for
- Simple, fast and easy to explain
- A great first model to compare others against
- Shows how much each feature matters
⚠ Watch out for
- Assumes a straight-line relationship
- A few extreme values (outliers) can pull the line badly
- Can't capture complex patterns on its own
Try it yourself
About 15 minDraw a best-fit line in a spreadsheet
- Type 8 rows: house size and price (made-up numbers that roughly rise together).
- Insert a scatter chart and add a linear trendline.
- Use the line to predict the price of a new size.
What you should see: You just trained and used a linear regression model.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.