Learning objectives
- Explain the ideas behind linear regression.
- Apply the ideas to the example and identify how you would check the result.
Concepts
A straight-line model predicts y = mx + b. The slope measures the change per unit of input and the intercept gives the prediction at zero. Least squares minimizes the sum of squared residuals.
Practical example
Estimate weekly orders from the number of active agents. Use the residuals to check which weeks the line misses.
Try the exercise
- Define the task. Estimate weekly orders from the number of active agents. Use the residuals to check which weeks the line misses.
- Identify the key idea. A straight-line model predicts y = mx + b.
- Check your decision. Describe an alternative and how you would compare its results.
Python example
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit([[1], [2], [3]], [2, 4, 6])
print(model.predict([[4]]))