33. Linear Regression in Python with sklearn
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
- No split. Always hold test rows (Chapter 31).
- Leakage. Do not include future rent or “final_price_paid” as a feature when predicting rent.
- Wrong problem type. Churn yes/no → logistic (Chapter 34), not LinearRegression.
- One wild outlier. A ₹9 lakh typo rent can tilt the line — clean first (Chapter 9 habit).
- 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.
Ravindra Bagale's Tip – मराठी
Model fit झाला म्हणजे तुमचा project संपला असं नाही. Test set वरचे predictions तपासा आणि ते numbers business च्या दृष्टीने योग्य वाटतात का, हेही पाहा. या दोन्ही तपासण्या झाल्यावरच तुमचा project पूर्ण होतो.
Ravindra Bagale's Tip – हिंदी
Model fit हो गया, इसका मतलब यह नहीं कि तुम्हारा project पूरा हो गया. Test set पर predictions जाँचो और यह भी देखो कि वे numbers business के हिसाब से सही लगते हैं या नहीं. इन दोनों जाँचों के बाद ही तुम्हारा project पूरा होता है.