# Who pays late? — a repayment-propensity model for chase prioritisation

A small, honest machine-learning project by Simran Jaiswal: predict which accounts will miss
their next payment, then turn the probabilities into a **ranked chase list with an economic
cut-off** — the AGE → RANK stages of the Leak Ledger, as a model.

Live case, with an in-browser scorer: https://simranjaiswal.in/work/who-pays-late

## Data

UCI Machine Learning Repository, *Default of Credit Card Clients* (Yeh & Lien, 2009).
30,000 credit-card accounts from a Taiwanese bank, April–September 2005: credit limit, age,
six months of repayment status, bill amounts and payment amounts, and whether the next
payment was missed (`default payment next month`, base rate 22.1%). Public, anonymised, real.

It is used here as a **stand-in for arrears data**: six months of "how late, how much billed,
how much paid" is the same shape as any receivables ageing history. What it is not: B2B
invoices, and not 2026. Read the limitations before reusing anything.

## Pipeline (`train.py`)

1. **Clean** — undocumented `EDUCATION` / `MARRIAGE` codes folded into "other"; `PAY_0` renamed
   `PAY_1` so the six months read 1 → 6 (most recent first).
2. **Features** (all known before the month being predicted, no leakage): months late now,
   worst month, count of late months, a recency-weighted lateness score, the lateness trend,
   utilisation now and on average, current bill and bill trend, share of the previous bill
   actually paid (mean and latest), zero-payment months, total paid in six months.
   Protected attributes (`SEX`, `AGE`) are **not** model features; `AGE` is kept only for
   group reporting.
3. **Split** — stratified 80/20 hold-out; 5-fold stratified CV on the training half.
4. **Models** — logistic regression (scaled) as the baseline; gradient boosting
   (`GradientBoostingClassifier`, 220 trees, depth 3, learning rate 0.05, subsample 0.8).
5. **Evaluation** — ROC-AUC, PR-AUC (the honest metric at a 22% base rate), Brier score,
   quantile calibration, lift by decile, AUC and mean score by sex and age band.
6. **Threshold economics** — accounts ranked by probability × exposure (current bill); a
   policy that contacts the top *k*% at a cost per contact and recovers a share of what would
   otherwise be missed. The page lets you move both parameters and watch the optimum move.
7. **Export** — the boosted trees to `model.json`; the page reproduces sklearn's probabilities
   in plain JavaScript (checked to < 1e-6). Per-account explanations use path contributions
   (Saabas): walking each tree, the change in node value at every split is credited to the
   splitting feature; the contributions sum exactly to the model's log-odds.

## Results (held-out 6,000 accounts)

| model | CV AUC | test AUC | test PR-AUC | Brier |
|---|---|---|---|---|
| logistic regression | 0.769 | 0.755 | 0.523 | 0.140 |
| gradient boosting | 0.785 | **0.781** | **0.564** | **0.134** |

Top-decile lift ≈ 2.9× the base rate. Group AUCs sit within ±0.01 of each other.

## Reproduce

```bash
python -m venv .venv && ./.venv/bin/pip install -r requirements.txt
# put the UCI file at data/default of credit card clients.xls, convert to CSV, then:
./.venv/bin/python train.py
```

## Limitations, stated plainly

- Consumer credit in Taiwan in 2005 is not your ledger. The *method* transfers; the *model* does not.
  Re-fit on your own history before trusting a single number.
- The economics are illustrative: cost per contact and recovery rate are inputs, not findings.
- A ranked list is a prioritisation tool for humans, not an automatic decision about a customer.
  In regulated collections, exclusions (vulnerability, disputes, kept plans) run before any score —
  see https://simranjaiswal.in/work/arrears-path.

## Files

- `train.py` — the whole pipeline, one file, deterministic (`SEED = 42`)
- `model.json` — exported trees and feature statistics for in-browser scoring
- `evaluation.json` — curves, calibration, lift, fairness, importance, a 1,000-account reference sample
- `requirements.txt`

MIT for the code. The dataset is © its authors and the UCI repository; cite:
Yeh, I. C., & Lien, C. H. (2009). *The comparisons of data mining techniques for the predictive
accuracy of probability of default of credit card clients.* Expert Systems with Applications, 36(2).
