The simplest and most useful predictive model.
Direct answer
Linear regression predicts a number by fitting a straight line through data. For one input the model is y = m·x + b. It finds the slope and intercept that minimise the squared errors between predictions and real values.
Example
from sklearn.linear_model import LinearRegression
import numpy as np
hours = np.array([[1], [2], [3], [4], [5]])
score = np.array([52, 58, 65, 70, 78])
model = LinearRegression().fit(hours, score)
print(model.coef_, model.intercept_)
print(model.predict([[6]]))
Measuring error
| Metric | Meaning |
|---|---|
| MAE | average absolute error |
| MSE | average squared error |
| R squared | share of variation explained |
Assumptions
- A roughly linear relationship.
- Errors that are not wildly uneven.
- Inputs not strongly overlapping.
Where Teyro fits
Teyro's Machine Learning for Beginners course turns this into short lessons you can play in a few minutes a day. It has 200 lessons, and you can start free.
The bottom line
A solid first model for numeric predictions.


