Machine Learning Fundamentals — Advanced
Why Accuracy Lies on Imbalanced Data
One-line idea: Accuracy (percent correct) looks great on a model that always predicts the majority class, if that class is common enough.
Everyday comparison: If only 1% of credit card transactions are fraudulent, a "model" that predicts "not fraud" for every single transaction is 99% accurate — and catches zero fraud. The impressive-looking number hides a completely useless model.
Common mistake + fix: Reporting accuracy as the headline metric for a rare-outcome problem (fraud, churn, disease detection). Fix: use precision, recall, and F1 (below) instead — they specifically expose how the model handles the rare class, which accuracy hides.
Memory line: High accuracy on rare-outcome data can mean "the model never even tries" — always check precision/recall before trusting an accuracy number.
Confusion Matrix, Precision, Recall, F1
One-line idea: A confusion matrix sorts every prediction into 4 buckets: correctly caught, wrongly flagged, missed, or correctly cleared.
Everyday comparison: A spam filter's confusion matrix works like a security checkpoint's log. It tracks real threats caught (true positives), innocent people wrongly stopped (false positives), real threats missed (false negatives), and innocent people correctly let through (true negatives).
Worked example: A churn model is tested on 15 customers. 5 actually churned; 10 didn't. The model predicted churn for 6 of the 15. Each cell below uses TP (true positive: churned and flagged), FP (false positive: stayed but flagged), FN (false negative: churned but missed), and TN (true negative: stayed and correctly cleared).
| Predicted churn | Predicted stay |
|---|
|---|---|---|
| **Actually churned (5)** | TP = 4 | FN = 1 |
|---|---|---|
| Actually stayed (10) | FP = 2 | TN = 8 |
Common mistake + fix: Optimising a model for the highest possible F1 score without asking which mistake (false positive or false negative) is actually more costly for this specific business problem. Fix: decide first whether missing a true case or wrongly flagging a false one is worse. Then prioritise recall or precision accordingly — F1 is a reasonable default only when both mistakes cost about the same.
Memory line: Precision asks "of what I flagged, how much was right?" Recall asks "of what was really true, how much did I catch?" The right balance depends on which mistake costs more.
ROC-AUC, Conceptually
ROC (receiver operating characteristic) and AUC (area under the curve) together form ROC-AUC, a single number that summarises a model's performance across every decision threshold.
One-line idea: ROC-AUC summarises how well a model separates two classes across every decision threshold — one number from 0.5 (random) to 1.0 (perfect).
Everyday comparison: Instead of judging a bouncer's "is this person over 21" calls at one specific strictness setting, ROC-AUC judges them across every possible setting at once. It summarises how well they can tell the two groups apart overall, regardless of exactly where the line is drawn.
Common mistake + fix: Using ROC-AUC as the only metric on a heavily imbalanced dataset, where it can look deceptively good. Fix: pair ROC-AUC with precision/recall at the actual threshold you plan to use in production — ROC-AUC describes overall separating power, not performance at your specific decision point.
Memory line: ROC-AUC asks "how well can this model tell the classes apart, across every threshold?" It doesn't tell you performance at the one threshold you'll actually use.
MAE and RMSE
One-line idea: MAE (mean absolute error) and RMSE (root mean squared error) both measure typical prediction error — RMSE punishes big errors more heavily.
Everyday comparison: If a weather forecaster is usually off by 1-2 degrees but occasionally off by 10 degrees, MAE treats that one bad day in proportion to its size. RMSE squares errors first, so that same 10-degree miss counts disproportionately worse, since squaring amplifies big errors more than small ones.
Worked example: A house-price model predicts 5 houses (₹ lakh): actual = 50, 62, 75, 88, 95; predicted = 48, 65, 70, 90, 100. Errors: 2, −3, 5, −2, −5.
RMSE (3.66) being higher than MAE (3.4) here reflects that the two 5-lakh errors are noticeably bigger than the rest — RMSE's squaring gives those two errors more weight than MAE's simple averaging does.
Common mistake + fix: Using the outdated mean_squared_error(y_true, y_pred, squared=False) pattern for RMSE. Fix: use root_mean_squared_error directly — a dedicated function added in scikit-learn 1.4, per scikit-learn's current API docs.
Memory line: MAE treats every error proportionally. RMSE punishes big errors extra hard, since it squares them first. A large gap between MAE and RMSE is itself a signal that a few predictions are badly off.
Thresholds and Class Imbalance
One-line idea: A classifier's default 0.5 threshold isn't special — moving it changes the precision/recall tradeoff, and the default is often wrong for the business.
Everyday comparison: A spam filter set to flag anything with even a 10% predicted chance of spam will catch almost all spam (high recall). But it will also wrongly flag a lot of real email too (low precision). Set to flag only 90%+ predicted spam, it'll rarely wrongly flag real email (high precision) but will let more actual spam through (lower recall). Same model, different threshold, very different behaviour.
Common mistake + fix: Always using the default 0.5 threshold without considering the actual cost of false positives vs. false negatives for this problem. Fix: choose the threshold deliberately, based on which mistake is costlier (see the precision/recall section above). For severely imbalanced data, also consider resampling or class weighting during training, not just a threshold adjustment after the fact.
Memory line: 0.5 is a default, not a rule. The right threshold depends on what each kind of mistake actually costs.
Model Monitoring Basics
One-line idea: A model that performed well at launch can quietly get worse as the real world changes — monitoring catches that drift early.
Everyday comparison: It's like a store's pricing strategy that worked great last year but hasn't adjusted for this year's changed customer habits. Nobody necessarily broke anything — the world just moved, and the old strategy quietly stopped fitting it.
Common mistake + fix: Shipping a model and never checking its real-world performance again. Fix: track the model's prediction distribution and, where possible, its real-world accuracy over time. A sudden shift in either signals that retraining — or at least investigation — is due.
Memory line: A model's accuracy on launch day isn't a permanent fact. The world changes under it — monitor, don't assume it stays good forever.
How Classic ML Relates to LLMs
One-line idea: Classic ML and LLMs solve different problems, but the same evaluation discipline — train/test thinking, watching for overfitting — carries over to evaluating LLM systems.
Classic ML models like the ones on this page are usually small, trained on your own structured data, and predict a specific number or category. LLMs are enormous, pre-trained on huge amounts of general text, and generate open-ended text or decisions.
The specific metrics differ. An LLM-based system is evaluated with the methods in ai/ai-evals (golden sets, LLM-as-judge) rather than a confusion matrix. But the underlying discipline is identical: never trust a number without a held-out test set, and always compare against a baseline. Watch for leakage too — an LLM eval set that's accidentally similar to the model's training data is the same failure mode covered in Intermediate.
The RAG systems covered in ai/rag also use classic retrieval-evaluation metrics, like precision and recall at the retrieval step. These are the same mathematical ideas as this page's precision/recall section, just applied to "did we retrieve the right documents" instead of "did we predict the right class."
Memory line: The tools differ — small trained models here, huge pre-trained models there — but "never trust an untested number" is the same rule in both worlds.

