← Learning Hub
Beginner

Your First Model: Linear Regression

Linear regression draws the best straight line through your data, then uses the line to predict. Let's predict a flat's monthly rent from its size.

Linear regression is the simplest predictive model and still widely used, because it's fast and easy to explain: each feature adds or subtracts a certain amount. Starting simple gives you a baseline that fancier models must beat.

Example
You can edit this code.

The model learned rent = intercept + coef × size. fit learns, predict uses what was learned - every scikit-learn model works this way.

More than one feature

Example
You can edit this code.

The negative number for distance means rent goes down as you move away from the metro - the model found that by itself.

A straight line is simple and easy to explain, so always try it first. Use fancier models only when they clearly do better.
Key points
  • Linear regression fits a straight line or plane.
  • Coefficients show each feature's effect.
  • Every scikit-learn model uses fit and predict.

📝 Test yourself

1. What does model.fit(X, y) do?
2. A negative coefficient for distance means...
3. Fill in the class for a straight-line model:
from sklearn.linear_model import