Machine Learning Basics·Machine learning from data to a responsible model

Regression

Predict a continuous value with linear regression and understand its assumptions.

Intermediate 15 min read Lesson 4 of 300 Challenge included
What you will be able to do
  • Use LinearRegression as the first baseline.
  • Inspect coefficients with feature names.
  • Check residuals for obvious patterns.
  • Use regularisation when features are many or correlated.

In plain English

Linear regression fits a line that minimises squared error. It is fast, interpretable and a strong baseline. Coefficients describe direction and size but not causation.

regression.pyPython
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LinearRegression().fit(X_train, y_train)
pred = model.predict(X_test)
print(mean_absolute_error(y_test, pred))
Your turn

Train a baseline

Easy

Fit a LinearRegression on the training split and predict the test split.

PYTHON · starter
model = LinearRegression()
Check your understanding before moving on.
Knowledge checkQuestion 1

What does a linear regression coefficient mean?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Classification
Lesson 4 of 300 · 0% of course