My classification model has 95% accuracy but is useless — why?

posée 4 months ago134 vuesen

6

I'm predicting fraudulent transactions. The model reaches 95% accuracy on the test set but catches almost no fraud. What's going on?

Diagnostic IA

Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.

posée 4 months ago

1 réponse

9
✓
✓ Réponse acceptée

Classic class imbalance. If 95% of transactions are legitimate, a model that always predicts "not fraud" gets 95% accuracy while catching zero fraud. Accuracy is the wrong metric here.

1. Use the right metrics: precision, recall and F1 for the fraud class, the confusion matrix, and PR-AUC (more informative than ROC-AUC for rare classes).

from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred, digits=3))

2. Handle the imbalance: class_weight='balanced' (or scale_pos_weight in XGBoost/LightGBM), or resampling on the training set only. 3. Tune the decision threshold. The default 0.5 is arbitrary. Pick the threshold from the precision-recall curve based on business cost: how expensive is a missed fraud versus a false alarm that blocks a customer? 4. Use a stratified split, and for fraud a time-based split, so you don't train on the future.

Connectez-vous pour dire si ça a marché.

answered 4 months ago

Sign in and verify your email to post an answer.