MACHINE LEARNING & AI
ML Fundamentals: Bias-Variance Tradeoff
3 min read
Understanding one of the most important concepts in machine learning — the bias-variance tradeoff and how it guides model selection.
The Bias-Variance Tradeoff
One of the most fundamental concepts in ML is understanding why models fail to generalize.
Decomposing Error
Total prediction error = Bias² + Variance + Irreducible Noise
flowchart LR
Model --> Underfitting
Model --> Overfitting
Underfitting --> HighBias["High Bias / Low Variance"]
Overfitting --> HighVar["Low Bias / High Variance"]
HighBias --> Fix1[More complex model]
HighVar --> Fix2[Regularization / More data]
Practical Tips
- Start simple — linear models first
- Diagnose with learning curves
- Use cross-validation to detect overfitting
- Regularization (L1/L2) reduces variance
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
model = Ridge(alpha=1.0)
scores = cross_val_score(model, X, y, cv=5, scoring='neg_mean_squared_error')
print(f'CV Score: {scores.mean():.3f} ± {scores.std():.3f}')