Skip to content

AI Engineer Interview Drill — 2026-11-30: ML Fundamentals

Nov 30, 20268 min
TL;DRAccuracy lies on imbalanced data. What actually matters is what bias-variance tells you about the failure mode, how L1/L2 fix it, which of precision/recall/F1 you should be optimizing, and whether your tuning loop quietly leaked into the test set — interviewers want to hear all five link together.

Look up & save

Loading dictionary…

中文版

Today's Focus

Monday's fixed slot is ML Fundamentals. Instead of drilling one isolated term, today's practice chains together a full diagnostic path for "why did this model disappoint in production": start with bias-variance to tell whether the model learned too little or memorized too much, move to how L1/L2 regularization fixes it, check whether the evaluation metric you picked is lying to you on imbalanced data, and finally circle back to whether the tuning loop actually used validation data or quietly leaked into the test set. These four get asked separately all the time, but what interviewers really want is whether you can walk the whole chain without dropping a step — exactly the kind of follow-up that shows up in ML system design rounds and take-homes.

Core Concepts

Bias-variance tradeoff: locate which side the problem is on

In one line: a model that's too simple misses the real pattern (high bias), and one that's too complex memorizes noise (high variance) — both inflate test error, and the relationship is ExpectedTestError = Variance + Bias² + IrreducibleError. The clearest way to show it: fit a linear model, a degree-4 polynomial, and a degree-15 polynomial to the same noisy data. The linear model scores poorly on both train and test — that's underfitting. The degree-15 model scores near-perfectly on train and drops sharply (sometimes negative) on test — that's overfitting on noise. The degree-4 model, scoring high and close on both, is the one you'd pick.

L1 vs. L2 regularization: different fixes, different side effects

Lasso (L1) can shrink some weights to exactly zero, which amounts to built-in feature selection. Ridge (L2) only shrinks weights toward zero without ever zeroing them out, so it keeps every feature. The choice depends on context: pick Lasso when only a handful of features actually matter, since it's easier to explain; pick Ridge when many features each contribute a little, since it's more stable. Worth flagging: when two features are highly correlated, Lasso tends to keep one and drop the other almost arbitrarily — a detail interviewers like to probe.

On imbalanced data, accuracy lies systematically

On a dataset that's 95% negative, a model that always predicts the majority class scores 95% accuracy while catching exactly zero positives — precision, recall, and F1 all come out to 0. That's why "99% accuracy" should always trigger the follow-up question "what's the class ratio?" — the lower the positive rate, the higher accuracy climbs just by guessing the majority class, with zero relationship to whether the model actually learned anything. Fraud detection, where well over 99% of transactions are legitimate, is the go-to scenario interviewers use to test whether your first instinct is to ask about the class distribution.

Precision vs. recall is a business-cost tradeoff, not a formula to recite

Precision = TP/(TP+FP), recall = TP/(TP+FN), and F1 is their harmonic mean; moving the decision threshold trades one for the other — a higher threshold raises precision and lowers recall. Which one to optimize depends on which error costs more: in fraud detection, missing a real case costs real money, so recall wins; in spam filtering, losing an important email to the spam folder costs more than letting one spam message through, so precision wins. One more trap: when negatives vastly outnumber positives, ROC-AUC can look deceptively good, because its false-positive-rate denominator is the entire negative class and a pile of false positives barely moves it — PR-AUC is the more honest read in that situation.

How you split train, validation, and test decides whether your score can be trusted

Validation data is for tuning hyperparameters and comparing models; test data gets touched exactly once, at the end. When data is scarce, k-fold cross-validation stands in for a single validation set and gives a more stable estimate. The most common mistake: trying ten hyperparameter values and keeping whichever one scores best on the test set. The moment you do that, the test set has effectively become a second validation set, and the reported score will look better than the model's real-world performance — because you just used it to pick a model.

How data flows across train, validation, and test — and the common "tuning on test" leak
How data flows across train, validation, and test — and the common "tuning on test" leakTraining, validation/tuning, and the final test each need separate data; tuning on the test set or re-checking it repeatedly turns it into a second validation set, making the reported score more optimistic than reality. Train model train set Tune / compare or k-fold Final test touch once Tuned on test becomes 2nd val set Reused repeatedly score too optimistic
  1. Train the model on the train set
  2. Tune hyperparameters and compare models on the validation set — or k-fold when data is scarce; using the test set for this instead turns it into a second validation set
  3. Touch the test set exactly once, at the end; re-checking the same test set across multiple models and keeping the best score makes the result look more optimistic than real-world performance

Simplified: when data is scarce, the validation step can be replaced by k-fold cross-validation.

Today's Practice Question

The question

You trained a credit-card fraud detection model with 99.2% overall accuracy, but the risk team reports that it keeps missing real fraud cases in production. They want you to explain the discrepancy and propose an evaluation approach they can actually trust.

Source: self-devised (a classic imbalanced-classification trap, common in fraud detection and anomaly-detection interview questions) Difficulty: Basic Round: phone screen

How to break it down

  1. Clarify first: Ask roughly what fraction of transactions are actually fraud (usually well under 1%), whether the current model selection and monitoring rely only on accuracy, and whether the risk team cares more about catching more fraud (recall) or bothering fewer legitimate customers (precision).
  2. Build a framework: Split the issue into two separate lines — "wrong metric" versus "model genuinely underperforms" — and verify by laying out the confusion matrix (TP/FP/FN/TN), computing precision, recall, and F1 directly, and checking whether the high accuracy is simply an artifact of how dominant the negative class is.
  3. Go deep on the core: Explain the precision-recall tradeoff — lowering the fraud-decision threshold raises recall at the cost of precision. Missing a fraud case (chargebacks, reputational damage, regulatory exposure) typically costs far more than flagging one extra legitimate transaction for review, so recall (or F2, a recall-weighted variant) should be the primary metric, with accuracy demoted to a secondary signal. Also note that with negatives so dominant, ROC-AUC can look deceptively strong, while PR-AUC better reflects performance on the minority class.
  4. Close it out: Land the answer on "the model probably isn't broken — we've been measuring it with the wrong ruler," and commit to following up with a precision-recall curve plus an adjustable threshold so the risk team can decide where to land.

Sample answer (say this out loud in the interview)

I'd frame "high accuracy but missed fraud" as a metric problem first, not necessarily a model problem. Fraud typically makes up well under 1% of transactions, so a model that learns nothing and always predicts "not fraud" would still clear 99% accuracy while catching zero real cases. I'd start by laying out the confusion matrix — TP, FP, FN, TN — and computing precision, recall, and F1 directly, to check whether recall is actually far lower than the headline accuracy suggests. If it is, the problem isn't necessarily that the model learned poorly; it's that we've been judging it with a metric that's meaningless at this class distribution.

From there I'd move the conversation to the precision-recall tradeoff. Lowering the threshold for flagging a transaction as fraud catches more real cases (recall goes up) but also misflags more legitimate ones (precision goes down). I'd walk the risk team through the actual cost math: missing a fraud case costs a chargeback plus eroded customer trust, which is almost always higher than the cost of one extra legitimate transaction getting a manual review — so I'd recommend recall, or F2 (a recall-weighted variant), as the primary metric instead of accuracy. I'd also flag that because legitimate transactions vastly outnumber fraud, ROC-AUC can look artificially strong here, and PR-AUC is the less misleading read.

Finally, I'd hand over something actionable rather than a unilateral call. I'd plot the precision-recall curve and let the risk team pick the recall/precision tradeoff — and the threshold that implies — themselves, rather than deciding for them. On the training side, I'd also suggest class_weight="balanced" or modest oversampling of the minority class, so the model itself is pushed to take the rare fraud class seriously during training, not just patched after the fact by moving the threshold.

Self-check

Use this table to check whether your answer hit the key points:

Check itemCovered?
Named accuracy's distortion on imbalanced data, rather than assuming the model is necessarily flawed
Used the confusion matrix to compute precision/recall/F1 instead of relying on accuracy alone
Tied the precision/recall tradeoff to actual business cost (missed fraud vs. false alarms)
Flagged that ROC-AUC can be misleading when negatives dominate, and that PR-AUC is more reliable
Mentioned addressing the imbalance during training (class weighting / oversampling), not just via a post-hoc threshold
Bonus: handed the threshold decision to the business side instead of deciding unilaterally

Further Reading

References