# Fraud decisions when the labels arrive late

When fraud labels (chargebacks, confirmed reports) arrive late, a fraud model is trained and watched on incomplete
truth. This study measures what that costs on public card data and which decision rule and monitoring rule hold up. The
page is `index.html`; the design, written before any test number, is `DESIGN.md`.

## What is here

- `fetch.py`: downloads the ULB credit card fraud data from OpenML and checks its sha256. No transaction row is in this
  folder.
- `fdl/`: the label delay simulation and the four label views (`labels.py`), the models (`models.py`), the decision
  rules, bootstrap and monitors (`decide.py`), the stage runner (`run.py`), the summary (`summarize.py`) and the page
  builder (`report.py`).
- `results/`: aggregates only. `cells/` holds one file per sweep cell and seed (per window, arm, model and rule:
  alerts, frauds caught, value caught, precision, cost; the monitoring checks), `stage-dev.json` the development
  precision behind the retrain floor, `stage-base.json` the bootstrap intervals, `stage-paired.json` paired intervals added after the test (fixed budget against cost rule, the gap in euros), `results.json` everything the page
  shows, `page-numbers.json` where each number on the page comes from.
- `tests/`: unit tests on small seeded arrays, and a replay test that rebuilds `results.json` and the page from the
  stage files and checks them against the committed bytes. No network and no data file needed.
- `tools/check_numbers.py`: every number a reader sees on the page must come from `results.json`.

## Reproduce

```
python -m venv .venv && .venv/bin/pip install -r requirements.lock
.venv/bin/python fetch.py
.venv/bin/python -m fdl.run all --data data/download/dataset_1597.pq
.venv/bin/python -m fdl.summarize && .venv/bin/python -m fdl.report
.venv/bin/python -m pytest tests -q
.venv/bin/python tools/check_numbers.py
```

The full run fits 4,800 models (20 delay settings, 5 seeds, 6 windows, 4 label views, 2 model families) on a laptop
CPU. Model
fits use threads, so the last digits of a refit can differ on another machine; the tests replay the committed stage
files instead.

## Data and licence

The data is the Credit Card Fraud Detection database of the Machine Learning Group of the Université Libre de
Bruxelles (ULB) and Worldline, published on OpenML as dataset 1597, under the Open Database License v1.0 with contents
under the Database Contents License v1.0. See `NOTICE.txt`.

Some files are packed in fraud-delayed-labels-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
