Skip to main content

How do you handle a heavily imbalanced classification problem, such as fraud detection?

Machine learning basics · Intermediate 2

Short answer

First pick the right metric: accuracy is useless when 99.5% of cases are normal, so use precision, recall, F1 or the area under the precision-recall curve. Then use class weights or resampling, tune the decision threshold for the business cost of each error, and validate with stratified splits.

Deeper answer

With one fraud case in two hundred, a model that always says "not fraud" is 99.5% accurate and worthless. The real question is the cost of a missed fraud versus a false alarm that annoys a customer, so agree that with the business before modelling.

Techniques: class weights so mistakes on the rare class cost more; undersampling the majority or oversampling the minority, done only inside training folds; models such as gradient boosting that cope well with imbalance; and choosing the threshold on a precision-recall curve instead of using 0.5. Use stratified cross-validation so each fold has some positive cases, and report results at the threshold you will actually use.

What a strong answer covers

Answer it out loud in the mock interview about 1.5 min

Follow-ups to expect

Common mistakes

Learn it

Choosing a metric

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.