Handbooks / Machine Learning Basics / Chapter 1
ML Foundations
7 pages · ~5 min✓ Reviewed
Start here. Next up: Linear and Logistic Regression.
Machine Learning BasicsPage 1Three Learning Paradigms
1. The Paradigms
- Supervised: learn X → y from labelled examples
- Regression = continuous value; classification = category
- Unsupervised: structure in unlabelled X only
- Clustering (k-means), PCA, anomaly detection
- RL: agent learns a policy maximising cumulative reward
- No labelled answers; feedback is delayed
- Agent
- Action
- Environment
- Reward
Quick testLabel, no label, or a reward?
3. Interview Point
- House price? Regression: the target is continuous
- RL vs supervised? RL gets delayed rewards, not a label per example
- Clustering accuracy? No: there are no true labels to compare against
Machine Learning BasicsPage 2Features, Labels and Data Splits
1. Data and the three sets
- Features = input columns X
- Label (target) = column y the model predicts
- One row = one example
2. Split choices
- Typical split: 60/20/20 or 70/15/15
- Imbalanced classes: stratified split
- Time series: time-ordered split, never random
3. Data leakage
Machine Learning BasicsPage 3Overfitting and Underfitting
2. Diagnose with Learning Curves
- Too simpleboth errors high
- Sweet spotval error minimum
- Too complextrain falls, val rises
- Plot error vs training size, or error vs model complexity
- Val error bottoms out, then rises as complexity grows
- The train-val gap is the overfit symptom
Machine Learning BasicsPage 4Bias-Variance Trade-off
1. Error Decomposition
- Expected error = bias² + variance + irreducible noise
- Noise is in the data: no model can remove it
- More complexity
- Bias falls
- Variance rises
- Sweet spotlowest total
Machine Learning BasicsPage 5Cross-Validation in Practice
1. k-fold CV
- Splitk folds
- Traink-1 folds
- Validate1 fold
- Rotatek times
- Averagek scores
- Usual choice: k=5 or 10
cross_val_score(model, X, y, cv=5) returns k scores
2. Splitters and Selection
GridSearchCV uses CV for model selection and tuning- Keep an untouched test set for the final score
Machine Learning BasicsPage 6ML Fundamentals Cheat Sheet
2. Splits
- Trainfit parameters
- Validationtune
- Testuse once
- Stratify for classes; order by time for time series
- Fit preprocessing on train only, then transform val/test
Machine Learning BasicsPage 7Check yourself
Train accuracy is 99%, test accuracy 70%. Diagnosis and one fix?
- Overfitting (high variance)
- The big train-test gap is the symptom
- Regularise, simplify or add data
Spot the bug: the scaler is fitted before splitting. What breaks?
- Data leakage: test statistics shape the scaler
- The score looks better than reality
- Fit on train only, or use a Pipeline
scaler = StandardScaler().fit(X)
X_tr, X_te = train_test_split(scaler.transform(X))
Train error 30%, validation error 31%. Will doubling the data help?
- No: both errors high and close means underfitting (high bias)
- Add capacity or better features instead
Why is random k-fold wrong for daily sales data?
- Future rows land in training folds, so the model peeks ahead
- The score is too optimistic
- Use TimeSeriesSplit