MACHINE LEARNING / 9. EVALUATION & PIPELINES
Evaluation & ML Pipelines
How to actually measure model quality — and automate the workflow
EXPLANATION
Choosing the right evaluation metric is as important as choosing the right model. Using the wrong metric gives you a false sense of performance. Classification metrics: • Accuracy → correct / total. Misleading for imbalanced data • Precision → TP / (TP + FP). How many predicted positives are actually positive • Recall → TP / (TP + FN). How many actual positives did we catch • F1 → harmonic mean of precision and recall. Balances both • AUC-ROC → area under ROC curve. Threshold-independent. Best for ranking Regression metrics: • MAE → mean absolute error. Robust to outliers • RMSE → root mean squared error. Penalizes large errors more • R² → proportion of variance explained. 1.0 = perfect, 0 = predict mean Cross-validation: never evaluate on training data. K-fold CV gives you a reliable estimate of generalization performance. sklearn Pipeline: chains preprocessing → model into one object. Prevents data leakage (scaler fit only on training fold), makes deployment clean.
DATA FLOW
Confusion Matrix (binary classification):
Predicted
Positive Negative
Actual Pos │ TP │ FN │
Neg │ FP │ TN │
Precision = TP / (TP + FP) ← "when I say positive, am I right?"
Recall = TP / (TP + FN) ← "of all positives, did I find them?"
F1 = 2 × P×R / (P+R) ← balance of both
K-Fold Cross Validation (k=5):
Fold 1: [val] [train] [train] [train] [train]
Fold 2: [train] [val] [train] [train] [train]
...
Final score = mean of 5 validation scoresCODE