Context
A BNPL provider has a few milliseconds at checkout to decide whether to lend. The data is synthetic: a seeded generator draws applications from a documented latent risk model (account age, repayment history, basket against usual spend, device recency, product category, plan length).
Problem
Approve too much and defaults climb. Decline too much and merchants lose sales. The decision also has to stay explainable and cheap to compute.
Technical choices
- Two stages. Deterministic knockouts run first: 2 or more previous defaults, 3 or more active plans, or a payment success rate under 60%. Only the rest reaches the model.
- One feature function. Training and serving both call
build_feature_frame, so a feature is computed the same way offline and online. - Calibrated probability, explicit thresholds. Under 0.15 the order is approved, between 0.15 and 0.35 it asks for an OTP or 2FA, above 0.35 it is declined. Thresholds are environment variables.
- Safe startup. The model loads once; if the artefact is missing, the service falls back to a transparent heuristic instead of failing.
Tests
- pytest on data generation, features, model and API.
- CI on GitHub Actions, and a Docker image for a one-command run.
Results
On 12,500 held-out applications: ROC-AUC 0.850, KS 0.540, Brier score 0.073. At the default threshold, about 79% of applications are auto-approved while the default rate among approved orders drops from 10.9% to 4.5%. Every number comes out of make train.