# Independent validation of a credit model

A credit default model is approved only after someone who did not build it checks every claim in its report on data
the developer never saw, and grades what they find. This study does that on public card data. An independent author
built the model from the development rows and wrote its report, without seeing the validation plan or the held-out
rows. The model, its code and its report were frozen by hash; the validation plan was written next; then it ran once on
12,000 held-out holders. The page is `index.html`; the design is `DESIGN.md` (Part 1 before the model was built, Part 2
after the freeze and before the validation run).

## What is here

- `fetch.py`: downloads the UCI archive and checks its sha256. No holder's row is in this folder.
- `cmv/data.py`: loads the spreadsheet and cuts the seeded 18,000 / 12,000 development and validation partitions.
- `author/`: exactly what the model's author received besides the development rows: the request (`BRIEF.md`, with
  the Python path filled in at run time) and the data dictionary. `tools/author_bundle.py` builds that folder.
- `developer/`: the delivered module `train.py` byte for byte, `REPORT.reading.md` (the delivered report with each
  range dash written as "to"; `reading-copy.json` holds both hashes), and `freeze.json` (hashes of the delivered
  files, of the fitted model and of its scores on the development rows). `tools/freeze.py` made the freeze.
- `cmv/developer.py`: loads the frozen module and refits the model, refusing it unless its development scores match
  the freeze.
- `cmv/metrics.py`, `cmv/validate.py`: the metrics, intervals and stability index, and the eleven checks and grade rules
  of `DESIGN.md` Part 2. `cmv/derive.py` and `cmv/render.py` build the page from the results.
- `results/`: aggregates only. `results.json` holds every check, claim, finding and prediction; `derived.json` the
  arithmetic the page shows on top of it; `page-numbers.json` where each number on the page comes from.
- `tests/`: unit tests on small seeded arrays, a replay test that rebuilds the page from the stored results and
  compares bytes, the number check with planted numbers, and the hash checks. No network and no data file needed.
- `tools/check_numbers.py`: every number a reader sees must come from the results files or a declared constant.

## Reproduce

```
python -m venv .venv && .venv/bin/pip install -r requirements.lock
.venv/bin/python fetch.py
.venv/bin/python -m cmv.validate data/download/uci350.zip
.venv/bin/python -m cmv.derive && .venv/bin/python -m cmv.render
.venv/bin/python -m pytest tests -q
.venv/bin/python tools/check_numbers.py
```

The validation refits the frozen model from `developer/train.py` and refuses to run if its scores on the development
rows differ from the freeze.

## Data and licence

Default of Credit Card Clients, by I-Cheng Yeh, UCI Machine Learning Repository, doi:10.24432/C55S3H, licensed under
Creative Commons Attribution 4.0 International (CC BY 4.0). See `NOTICE.txt`.

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