Methodology
How the dataset, features, and model were built.
1. Dataset
The dataset is synthetic and deliberately realistic. It contains 5,000 clients with income, occupation, risk rating and a home province; and 100,000 transactions spread across a four-year observation window (January 2022 to September 2026). Fraud is injected at a rate of 1.7%, using five distinct fraud patterns:
- Account takeover — new device, foreign login, overnight hour, unusually large transfer.
- Card compromise — new device, POS or online, mismatched payment method.
- Velocity attack — many consecutive transactions within minutes.
- Geographic anomaly — transaction far from the client's home province.
- Merchant anomaly — high-risk merchant category the client has never used.
2. Feature engineering
Every feature is computed with strict temporal discipline — no feature may use any transaction with a timestamp equal to or later than the transaction being scored. This avoids the most common source of inflated fraud-detection accuracy.
82 predictors are grouped into nine families:
- Temporal — hour, day of week, weekend, night-time, business hours.
- Balance — change, ratios, whether the account went negative.
- Velocity — transactions and amounts in rolling 10min/1h/6h/24h/7d windows.
- Behavioural — each client's own average, median, max, standard deviation.
- Sequence — time and amount since the previous transaction.
- Location — distance from home, distance from previous transaction, new-city flags.
- Device — new device flags, per-client device counts, cross-client device usage.
- Merchant — new merchant, merchant-level amount and frequency statistics.
- Interactions — amount vs income, amount vs monthly spend, channel preference matches.
3. Models compared
A Logistic Regression baseline with class balancing, median
imputation, and one-hot encoding provides a reference point.
XGBoost handles the nonlinear interactions and class imbalance
natively via scale_pos_weight. The model with the
higher PR-AUC on the validation set becomes the production model.
4. Evaluation
Accuracy is meaningless for imbalanced fraud detection. The primary metric is PR-AUC (average precision), supported by ROC-AUC, recall at precision ≥ 0.5, F1 at the best threshold, and recall broken down by transaction segment (night, large amount, new device, international, and so on).
5. Explainability
Every prediction is accompanied by SHAP values — one number per feature, saying how much that feature moved the fraud probability up or down relative to the base rate. This makes the model auditable: analysts can see exactly which inputs drove a flag.
6. Limitations
The synthetic fraud generator lets fraudulent transactions overdraw the account, so balance-level features carry an unusually strong signal here. In real banking this pattern is present but weaker, because most fraud keeps the balance positive. Other limitations: no beneficiary/payee features, no IP geolocation, no cross-institution signals.