KatInterview

Handle Class Imbalance in Fraud Detection

Machine LearningModel answer
MediumModel answerMachine Learningmachine learningclass imbalancefraud detection

Last updated

Design and evaluate an ML pipeline for detecting rare fraudulent transactions, navigating class imbalance at every stage from data to deployment.

Scenario

You are an ML engineer at a payments company. The risk team hands you a labeled dataset of 50 million transactions from the past 12 months. Only 0.08% of them are confirmed fraud — roughly 40,000 positive examples.

Your task is to build a production model that flags fraudulent transactions in near-real-time (within 200 ms). The business cost of a false negative (missed fraud) is roughly 20× higher than the cost of a false positive (incorrectly flagging a legitimate transaction).


What the interviewer expects

Walk through your entire approach as if presenting to a senior ML team. Specifically address:

  1. Problem framing — how do you account for the asymmetric cost and class imbalance from the start?
  2. Data preparation — which resampling or weighting strategies would you consider, and what are their trade-offs?
  3. Model choice and training — what algorithms are well-suited, and how do you configure them for imbalance?
  4. Evaluation — which metrics do you use and why? Which metrics would mislead you here?
  5. Threshold selection — how do you pick the decision threshold given the cost asymmetry?
  6. Deployment concerns — what drift or feedback-loop issues should you watch for in production?

Be concrete: mention specific techniques, justify choices with trade-offs, and flag common mistakes.

Hints

Hint 1

Accuracy is ~99.92% if you predict all-legitimate — what does that tell you about which metrics to use?

Hint 2

Think about the 20:1 cost ratio when choosing your resampling strategy and when setting the classification threshold — these are two different levers.

Hint 3

Fraud patterns shift over time as fraudsters adapt. How does that affect your data pipeline and monitoring strategy?