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.
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.
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.
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
Fraud rate by IP-risk tenth
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.
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
Model: top 1,299 by score
Verdict
A tie.
The model doesn't rank fraud better than the rule. I said so in the notebook rather than hide it.
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.

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.
04 · bOn the untouched test weeks, at 0.085
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 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.

Odds of fraud, multiplied by
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.