Ravindra BagaleCourses & study guides मराठी Track your progress

33. Linear Regression in Python with sklearn

Data Science

33.5 Common Linear Regression Mistakes

Why. Beginners often get a running notebook that is still wrong for business. Spot these traps early.

What. Common linear-regression mistakes: fitting on all rows with no test set; putting the label inside X; expecting a perfect line on messy data; forgetting units (₹ vs lakhs); using linear regression for a clear yes/no target.

How.

Mistake checklist

  1. No split. Always hold test rows (Chapter 31).
  2. Leakage. Do not include future rent or “final_price_paid” as a feature when predicting rent.
  3. Wrong problem type. Churn yes/no → logistic (Chapter 34), not LinearRegression.
  4. One wild outlier. A ₹9 lakh typo rent can tilt the line — clean first (Chapter 9 habit).
  5. Over-trust R² on 10 rows. Tiny samples look perfect; they are not proof.
# BAD: label inside features
# X_bad = df[["area_sqft", "rent_inr"]] # never do this

# GOOD
X_good = df[["area_sqft"]]
y_good = df["rent_inr"]
assert "rent_inr" not in X_good.columns

Ravindra Bagale's Tip

Fitting the model does not mean your project is finished. You also need to check the predictions on the test set and ask whether the numbers make business sense. Your project is complete only when both of these checks are done.