Lesson 5 of 18 · 2 min
Step 1 of Learning: Simple Linear Regression First
Before multiple regression, understand simple regression with ONE feature.
Real-world analogy: You want to predict house price using only the area (size). Bigger house = higher price. Draw a straight line through that relationship.
Formula: Price = m × Area + b
- m = slope (how much price changes per extra sq ft)
- b = intercept (base price when area = 0)
Manual example (3 houses):
| Area (sq ft) | Price (₹) |
|---|---|
| 1000 | 50,00,000 |
| 1500 | 70,00,000 |
| 2000 | 90,00,000 |
Pattern: every 500 sq ft adds ₹20,00,000. Slope = 4,000 per sq ft. Intercept = 10,00,000.
So: Price = 4000 × Area + 10,00,000
Predict for 1800 sq ft: Price = 4000 × 1800 + 10,00,000 = ₹82,00,000
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
# Simple example: area vs price
area = np.array([1000, 1500, 2000, 2500, 3000]).reshape(-1, 1)
price = np.array([5000000, 7000000, 9000000, 11000000, 13000000])
model = LinearRegression()
model.fit(area, price)
print(f"Slope (m): {model.coef_[0]:,.0f}") # price increase per sq ft
print(f"Intercept (b): {model.intercept_:,.0f}") # base price
# Predict for 1800 sq ft
predicted = model.predict([[1800]])
print(f"Predicted price for 1800 sq ft: ₹{predicted[0]:,.0f}")
# Plot
plt.scatter(area, price, color='blue', label='Actual')
plt.plot(area, model.predict(area), color='red', label='Regression Line')
plt.xlabel("Area (sq ft)")
plt.ylabel("Price (₹)")
plt.title("Simple Linear Regression — Area vs Price")
plt.legend()
plt.show()
Now you understand simple regression. Multiple regression is the same idea — just more features.
