Editor

Complete Regression Pipeline

Intermediate · Write the code · from Build Your First ML Model: Linear Regression with scikit-learn

From the lesson: Build Your First ML Model: Linear Regression with scikit-learn

Imagine you're a real estate agent. A client asks, "How much is my house worth?" You look at the square footage, the number of bedrooms, and the neighborhood - then you give an estimate. You just did regression in your head.

Read the lesson

Build a complete pipeline: generate data with make_regression(n_samples=150, n_features=4, noise=20, random_state=0), split 75/25 with random_state=0, scale with StandardScaler (fit on train only), train LinearRegression, and print the RMSE on the test set rounded to 2 decimal places. Use np.sqrt(mean_squared_error(...)).

from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
from sklearn.metrics import mean_squared_error
import numpy as np
# Build the full pipeline

More Linear Regression exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz