Regression: Predicting a Number
Regression = predicting a continuous number: a price, a temperature, a delivery time. Linear regression finds the best straight-line relationship between your features and that number.
More than one feature
Real predictions use several inputs. Here, price depends on both rooms and area. model.coef_ now has one number per feature — the effect of that feature, holding the others fixed. That interpretability is why linear models are still everywhere in industry.
Two metrics you must know
- MAE — average absolute error, in the label's units. "We're off by ₹4.1 lakh on average."
- R² (r-squared) — the fraction of the variation the model explains, from 0 to 1.
1.0is perfect;0.0is no better than always guessing the mean. Above ~0.7 is usually "this feature set actually carries signal."
Which to report?
Report both. R² tells you whether the features explain the target at all; MAE tells you how wrong you'll be in practice. A model can have a decent R² and still be too imprecise to ship — MAE catches that.
Try it
- Which matters more here — an extra room, or 100 more sq ft? Read the coefficients.
- Split into train/test (last lesson) and compare test R² to the R² above. Is the model as good on unseen homes?
3 graded exercises
Write the code, click Check. We’ll tell you exactly what to fix.
- Exercise 1
Write
r2(model, X, y)returning the R² of the model's predictions onXvsy. - Exercise 2
Two features
[rooms, area]. Writebiggest_driver(model)returning"rooms"or"area"— whichever feature has the larger coefficient. - Exercise 3
Write
predict_price(model, rooms, area)returning the predicted price for one home.