← All projects

Case study · Fraud analytics

  • Binary classification
  • Imbalanced data
  • Risk scoring

Which payments should we stop?

50,000 digital payments across UPI, cards, net banking and wallets, about one in ten of them fraud. I validated the data, tested every suspected signal, raced four models through time-ordered cross-validation, priced every false alarm, and turned the result into a risk score with four actions. The most useful finding was an uncomfortable one.

50,000transactions, Jan–Mar 2024
10.06%of them fraud
74.9%of test fraud caught at the cost-optimal threshold

Step 01 · Trust the data first

22 checks. Three surprises.

Before any model, I checked keys, missing values, ranges, business rules and dates, and logged every result. Nothing was missing and nothing was duplicated, but three things didn't add up.

22validation checks, every one logged
4,121rows with zero transactions in 24 h but a non-zero 24 h average: set to missing
15of 25 columns match the data dictionary's names
10.06%fraud rate, against “under 0.5%” in the documentation

Documented fraud rate vs actual

<0.5% → 10.06%

20 times more fraud than described. That changes how “imbalanced” this really is: about 1 fraud per 9 genuine.

Why it matters

Every merchant appeared under all six categories and customers averaged 12.5 devices, so IDs couldn't be treated as stable profiles. The file also wasn't in time order. I sorted it and split by time: train on January to early March, validate on the next two weeks, test on the last two. The model is always tested on the future, as it would be in production.

Step 02 · Find the real signal

Three signals. Everything else is noise.

Fraud playbooks say watch big amounts, late nights, weekends and risky categories. I tested 19 columns with chi-square and Mann-Whitney tests, Bonferroni-corrected. First, a guess: which raises the fraud rate more?

Fraud rate · device × location change

Location sameLocation changed Device same
6.9%82.9% of payments
22.4%location only
Device changed
26.8%device only
42.8%both · 388 payments

Fraud rate by IP-risk tenth

Lowest 10%5.4%
2nd6.6%
3rd8.1%
4th8.1%
5th9.0%
6th10.4%
7th11.9%
8th12.8%
9th13.9%
Highest 10%14.3%
The flat ones

Amount, hour, weekday, merchant category, payment method, authentication, device trust and nine customer-history features all sit near an AUC of 0.50 (a coin flip). Only device change, location change and IP risk survive the tests with a meaningful effect. And about 57% of fraud shows none of the warning signs: no new device, no new location.

Step 03 · The model race The hard part

Four models, 30+ features. The same ceiling.

03 · aEverything lands near 0.22

I built 24 row-level features (time, amount spikes, velocity, identity changes) and 9 history features that only look backwards in time, then compared four models with five-fold time-ordered cross-validation. The score is PR-AUC: how well a model ranks fraud above genuine, where random scores about 0.10.

Sort:
    cross-validated PR-AUC (0.10–0.25 scale)validation PR-AUC

    Class weights, oversampling and undersampling changed PR-AUC by less than 0.01 in every combination. An ablation adding feature groups one at a time was just as flat. The final model is logistic regression on four raw columns: IP risk, device change, location change and international.

    03 · bThe uncomfortable test

    The model vs a one-line rule.

    The fair comparison isn't against random. It's against the simplest rule an analyst would write: flag the payment if the device or the location changed. On the test weeks, flagging the same 1,299 payments:

    Rule: device OR location changed

    Precision25.7%
    Recall44.2%

    Model: top 1,299 by score

    Precision25.3%
    Recall43.5%

    Verdict

    A tie.

    The model doesn't rank fraud better than the rule. I said so in the notebook rather than hide it.

    So why keep a model?

    A rule gives a yes or no. The model gives a calibrated probability, which can be cut into tiers: let most payments through, challenge some with an OTP, send a few to a person, block the worst. That graded response is where the value is. The real limit is the data: with 57% of fraud showing no warning sign, no model on these columns can catch it.

    Test-set ROC curve with AUC 0.718 against 0.706 for a hand-built risk index, precision-recall curve with PR-AUC 0.231 against a 0.101 base rate, and a cumulative gains curve
    Test weeks: ROC-AUC 0.718, PR-AUC 0.231 (2.3x the base rate), and the riskiest 20% of payments hold 47.5% of the fraud.

    Step 04 · Price the mistakes

    The threshold is a business decision.

    A missed fraud costs its amount plus a ₹300 chargeback fee. A false alarm costs customer friction. Nobody gave me that second number, so I tried six and let the cheapest threshold fall out of each. Drag the cost of one false alarm.

    Cost of one false alarm₹1,000
    0.085cheapest threshold
    ₹27.9 Lsaved on the two validation weeks
    Payments flagged48.5%
    Fraud caught (recall)73.0%
    Flags that are fraud16.0%

    04 · bOn the untouched test weeks, at 0.085

    566frauds caught (true positives)
    190frauds missed, all with no device or location change
    3,022genuine payments challenged
    ₹30.4 Lmodelled net saving, vs ₹5.9 L for random flagging

    Step 05 · From probability to action

    Score a payment. Live.

    This is the final model, running in your browser with its saved coefficients, scaling and calibration: the same numbers the notebook's scoring function returns. Set the four inputs and watch the tier change.

    the real model, in your browserlogistic regression + Platt calibration
    Risk score (0–100) 0.0
    Tier Action

    The highest score any input combination can reach is about 71: the model is never certain, because 57% of fraud looks exactly like genuine payments on these four columns.

    Permutation importance: device change highest, then location change, then IP risk, international barely above zero
    Shuffle a column and see how much PR-AUC drops: device change matters most.

    Odds of fraud, multiplied by

    Device changed4.86×
    Location changed3.72×
    IP risk 0 → 13.51×
    International1.44×

    Read from the logistic regression's coefficients: easy to explain to a risk team.

    • Get data for quiet fraudBehavioural biometrics, payee history or device fingerprint details: the 57% with no warning sign needs new columns, not new models.
    • Measure the real friction costThe threshold rests on an assumed ₹1,000 per false alarm. Real drop-off data from OTP challenges would pin it down.
    • Monitor drift weeklyFraud patterns move. Track precision and recall per tier and retrain when they slide.

    The lesson

    Beat the simple rule, or say you didn't.

    The model's worth here isn't sharper ranking; it's a calibrated score that turns into four proportionate actions. Knowing which is which is the part that would survive contact with a real risk team.

    Python · pandas · SciPy · scikit-learn · Matplotlib · Seaborn. Synthetic data for PaySphere, a fictional payments company.