Understand and implement linear regression — the foundation of supervised learning — with gradient descent and scikit-learn
Linear regression is the simplest and most interpretable ML algorithm. It assumes a linear relationship between input features and the target variable.
ŷ = w₁x₁ + w₂x₂ + ... + wₙxₙ + b
ŷ = w₁x₁ + w₂x₂ + ... + wₙxₙ + b
Where:
We want to minimise the difference between predictions and actual values:
MSE = (1/n) × Σ(yᵢ - ŷᵢ)²
MSE = (1/n) × Σ(yᵢ - ŷᵢ)²
w = w - α × ∂MSE/∂w
w = w - α × ∂MSE/∂w
Where α (alpha) is the learning rate — how big each step is.
| Metric | Formula | Interpretation |
|---|---|---|
| MSE | mean((y - ŷ)²) | Average squared error |
| RMSE | √MSE | Same units as target |
| MAE | mean( | y - ŷ |
| R² | 1 - SS_res/SS_tot | % variance explained (0-1) |
to use AI code explanations