MACHINE LEARNING / 1. LINEAR REGRESSION
Linear Regression
Predicting continuous values — the foundation of everything
EXPLANATION
Linear regression models the relationship between features X and a continuous target y as a straight line (or hyperplane in higher dimensions). ŷ = w₁x₁ + w₂x₂ + ... + wₙxₙ + b = Xw + b Training = finding w and b that minimize Mean Squared Error: MSE = (1/n) Σ(yᵢ - ŷᵢ)² Closed-form solution (Normal Equation): w = (XᵀX)⁻¹Xᵀy Works perfectly for small datasets. For large datasets, use gradient descent. Key assumptions: • Linear relationship between X and y • Features are independent (no multicollinearity) • Residuals are normally distributed with constant variance Regularization prevents overfitting: • Ridge (L2) → penalizes large weights, shrinks all weights • Lasso (L1) → drives some weights to exactly zero (feature selection) • ElasticNet → combines both L1 and L2
DATA FLOW
Data points: ● ●
● ●
● ●
● ●
Linear fit: ─────────────────── ŷ = wx + b
Residuals (errors):
● ↕ (y - ŷ) for each point
───────────────────────────────────
Goal: minimize sum of squared residuals
Ridge adds: λΣwᵢ² → shrinks weights
Lasso adds: λΣ|wᵢ| → zeroes out weightsCODE