Regression
Predict a continuous value with linear regression and understand its assumptions.
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.
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
EasyTrain a baseline
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.