Linear Regression
Machine Learning · Beginner
Definition
Linear regression predicts a continuous value by fitting a straight line y = mx + c that minimises squared error.
It is the simplest predictive model and the base for understanding ML.
Diagram
Flowchart
Example: Closed-form fit
import numpy as np
x = np.array([1,2,3,4]); y = np.array([3,5,7,9])
m, c = np.polyfit(x, y, 1)
print(round(m,2), round(c,2))Output: 2.0 1.0
Complexity
Evaluate with MSE, RMSE, R²
Key points
- Assumes linear relationship
- Sensitive to outliers
- Regularisation: Ridge, Lasso
Interview questions
What does R² mean?
The share of variance in y explained by the model (1 is perfect).