02 · See it in action
Follow the steps
- Create a small synthetic input and numeric target.
- Fit a linear regression model.
- Compare predictions with held-out observations.
- Inspect residuals, the difference between observed and predicted values.
Worked example
from sklearn.linear_model import LinearRegression
x = [[1], [2], [3], [4]]
y = [3, 5, 7, 9]
model = LinearRegression().fit(x, y)
print(model.predict([[5]])) # approximately [11.]
Read the example once, then explain each part aloud in your own words. If it includes Python, you can understand the idea first and run the code later in a local Python environment. Code is shown as text; this page does not execute it.
Sign in to save your reading progress.
Sign in