Machine Learning · medium · Asked at Stripe
Asked in Data Scientist interviews, in the Machine Learning round.
Precision, recall, PR-AUC, F-beta; avoid raw accuracy; consider cost-weighted metrics.
Not accuracy. With 0.2% fraud, a model that flags nothing is 99.8% accurate.
The metrics that describe a fraud model's actual job:
Then turn it into money. A missed fraud costs the transaction; a false block costs a customer, some of whom leave. Put those two costs on the confusion matrix and choose the threshold that minimises expected cost. That is the answer to "which is more important, precision or recall": it depends on the two prices, and you can compute it.
from sklearn.metrics import average_precision_score, precision_recall_curve
ap = average_precision_score(y_val, scores) # PR-AUC
prec, rec, thr = precision_recall_curve(y_val, scores)
Mention that fraud drifts, so the metric must be reported on recent data, and that evaluation must respect time: train on the past, test on the future.