# Design: independent validation of a credit model

This file is written in two parts. Part 1 (data, partitions, how the model under test is made and frozen) was
committed before the model's author started. Part 2 (the validation plan) is committed after the model, its code and
its report are frozen by hash, and before any validation number is computed. The commits record when each part was
declared; `design-declaration.json` holds each part's sha256. Anything added later is labelled as added later, with why.

## Question

Given a frozen credit default model built by someone else, what does an independent validation find that the
developer's own report does not, and which of those findings should block approval?

## Part 1. Data, partitions and the model under test

### Data

- UCI Machine Learning Repository dataset 350, "Default of Credit Card Clients" (Yeh, 2009, DOI 10.24432/C55S3H),
  licensed CC BY 4.0. Archive `https://archive.ics.uci.edu/static/public/350/default+of+credit+card+clients.zip`,
  sha256 `56c885f84457f6680f8438f02bfcdac9579323d8a94465ee5f26e32baa727602`; the spreadsheet inside it,
  `default of credit card clients.xls`, sha256 `30c6be3abd8dcfd3e6096c828bad8c2f011238620f5369220bd60cfc82700933`.
  `fetch.py` refuses other bytes.
- 30,000 card holders of one bank in Taiwan, 2005: credit limit, sex, education, marital status, age, six months of
  repayment status, bill amounts and payments (April to September 2005), and whether the holder defaulted on the next
  payment (the outcome, 22.1% of rows).
- No row is committed or published. Every published file holds aggregates over at least 30 holders, or settings.

### Partitions

- Rows in ID order, permuted with `numpy.random.default_rng(350)`. The first 18,000 of the permutation are the
  development partition, the other 12,000 the validation partition (`cmv/data.py`).
- Fingerprints (sha256 of the partition's IDs, one per line, ascending): development
  `40f9ff84d0115e54cb0fd61febcd27da95ea39c26f2dff3f8c35847394d6318d`, validation
  `1f6de2b5b6f321a43c4de82563d245bbe076b413f63de34901a3032c282ebaff`.
- The data holds a single outcome month, so no true out-of-time test exists. Part 2 declares what stands in for one.

### The model under test, built by an independent author

- An independent author builds the development model and writes its development report. It works in a folder that
  holds only `dev.csv` (the development partition, all 25 columns), the data dictionary (`author/DATA_DICTIONARY.md`:
  the column names and the source's own variable description, quoted) and the brief (`author/BRIEF.md`). The brief
  asks for "a default model for card approvals" and a report of its performance, plus a recommended approval cutoff,
  and fixes only the delivery format: a module with `fit(df)`, `score(model, df)` and `CUTOFF`, and a report.
- The author never sees this file's Part 2, the validation partition, this study's code or any validation result.
  Part 2 does not exist while the author works. The author runs once; there is no second attempt and no feedback.
- The author's folder is read-only, so it fits and evaluates in memory. Its record of commands is kept and checked
  afterwards for any read outside its folder.
- The author's inputs and outputs are hashed.

### Freeze

- The delivered module is saved byte for byte as `developer/train.py`, the report as `developer/REPORT.md`.
- The frozen model is `fit(development partition)` run once with the pinned packages; its pickle's sha256 and the
  sha256 of its scores on the development partition (rounded to 12 decimals) go in `developer/freeze.json` with the
  sha256 of both delivered files. The freeze is committed before Part 2 is written.
- Nothing in `developer/` changes after the freeze. If the module fails to run as delivered, that is recorded as a
  finding, and the smallest change that makes it run is made in a separate, labelled file.

## Part 2. Validation plan

Written after the freeze and after reading the developer's report, before any number from the validation partition
was computed. The validator does not change the model. Every out-of-sample number comes from the 12,000 validation
rows; the development partition is used only to refit the developer's own procedure and the challengers.

### Intervals and seeds

- Bootstrap: 1,000 resamples of validation rows, seed 7, percentile 95% intervals. A difference between two models or
  two cutoffs uses the same resamples for both (paired). A rate within a group uses the Wilson 95% interval.
- The cross-fit halves of the validation partition: seeded permutation, seed 11, 6,000 rows each.
- Proxy-strength cross-validation: 5 stratified folds, seed 0.

### Grades (the rule for each, set here)

- **Blocks approval:** the model cannot be approved for the decision it was submitted for until it is rebuilt or the
  decision is redefined. (B1) Its inputs need data the submitted decision does not have. (B2) The validation's 95%
  interval lies wholly on the unfavourable side of the report's claimed AUC, or of its claimed default rate among
  approved holders at the recommended cutoff.
- **Fix before use:** a bounded change, without a rebuild, is needed first. (F1) Calibration: a score band next to the
  cutoff (0.15 to 0.20, or 0.20 to 0.25) is miscalibrated, or three or more of the seven bands are. A band is
  miscalibrated when the Wilson interval of its observed default rate excludes its mean predicted rate. (F2) Cutoff: at
  the declared costs, the recommended cutoff costs more than the cross-fitted cutoff, with a paired interval excluding
  zero, in both halves. (F3) Freshness and stress: AUC falls by more than 0.03 with a paired interval excluding zero
  under the stale feed, or a stress population's calibration gap (observed minus mean predicted default rate) has an
  interval excluding zero and a point beyond 2 points. (F4) Protected traits: any group's approval rate is below 0.80
  times the highest group's, or a group's calibration gap has an interval excluding zero and a point beyond 2 points.
  This is a screening trigger for a fair-lending review, not a legal finding. (F5) A report number that its own
  described procedure does not reproduce (beyond its rounding) by more than 0.005 in AUC or 1 point in a rate. (F6) A
  numeric claim other than those in B2 whose validation interval lies wholly on the unfavourable side. (F7) A declared
  challenger beats the model on AUC with a paired interval excluding zero.
- **Note:** everything else measured: differences inside their intervals, a band miscalibrated away from the cutoff,
  a population stability index (PSI) above a threshold with calibration holding, data defects with no measured effect on a
  decision, a challenger within 0.01 AUC.

### Checks

1. **Intended use.** List the frozen model's inputs from its code and count those that need account history. The
   brief asked for a model for card approvals; if the inputs need history an applicant does not have, that is B1 for
   applicant approvals, and the other checks treat the score as what it is.
2. **Reproduction.** Refit with the report's own described test split (StratifiedGroupKFold, 5 folds, shuffled, seed
   20261023, groups the hash of the 19 financial inputs, first split) and recompute every number in the report's test
   tables: AUC, average precision, log loss, Brier score, mean prediction and observed rate, the quintile table, the
   approval table at 0.20, approval rate, default rate among approved, the shares of defaulters declined and
   non-defaulters approved, the cost per holder at 4:1 and the two all-or-nothing policies, and the approval and default
   rates by sex. Grade by F5.
3. **Discrimination on the validation partition.** AUC, average precision, log loss, Brier score, KS, with intervals.
   Each against the report's claim: holds (claim inside the validation interval), weaker than claimed (interval wholly
   on the unfavourable side) or better than claimed. Grade by B2 and F6.
4. **Calibration.** (a) The report's quintile table recomputed on the validation partition (quintiles of validation
   scores), each row against the claimed row. (b) Seven fixed score bands: 0 to 0.10, 0.10 to 0.15, 0.15 to 0.20, 0.20
   to 0.25, 0.25 to 0.35, 0.35 to 0.50, 0.50 and above; mean predicted against observed, with Wilson intervals. (c)
   Calibration in the large, with a bootstrap interval of the gap. Grade by F1.
5. **Stale feed, the stand-in for an out-of-time test.** The data has one outcome month, so the same holders are scored
   as if the file were a month old: every monthly column moves one month back (September takes August's value, and so
   on), April's value is repeated, and the outcome is unchanged. This measures how much the model leans on the latest
   month, not drift over time. AUC (paired difference), mean predicted against observed, approval rate and default rate
   among approved at 0.20, PSI. Grade by F3.
6. **Stability under declared stresses.** PSI on 10 bins, the deciles of the frozen model's scores on the development
   partition; under 0.10 stable, 0.10 to 0.25 watch, above 0.25 shifted (common industry thresholds, used as
   conventions). Populations: S0 the validation partition as it is (bookkeeping: a random split has a PSI near zero by
   construction); S1 holders aged 30 or under weighted 3; S2 credit limits of NT$50,000 or less weighted 3; S3 holders
   with any payment delay in the six months (any status of 1 or more) weighted 3; S4 the stale feed. For each: PSI,
   weighted AUC, calibration gap, approval rate and default rate among approved at 0.20. Grade by F3.
7. **Challengers,** fitted on the development partition, scored on the validation partition. (A) L2 logistic regression
   on the developer's 19 raw financial inputs, standardised, C = 1, at most 2,000 iterations. (B) The latest repayment
   status alone (PAY_0 as the score), and the rule "approve when PAY_0 is 0 or below". Paired AUC differences. Grade by
   F7, else note.
8. **Protected traits,** at the cutoff of 0.20 on the validation partition. Groups: sex (male, female); age (30 or
   under, 31 to 40, 41 to 50, over 50); marital status (married, single, other, where other merges codes 0 and 3);
   education (graduate school, university, high school, other, where other merges codes 0, 4, 5 and 6). Approval rate,
   its ratio to the group with the highest rate, default rate among approved, calibration gap. Proxy strength: the
   5-fold cross-validated AUC of a gradient boosting classifier (scikit-learn defaults, random_state 0) predicting
   female, aged 30 or under, single, and graduate school from the 19 inputs. Score invariance: the scores do not change
   when ID and the four trait columns are shuffled. Grade by F4.
9. **Decision.** Declared costs, both assumptions: approving a holder who then defaults costs US$2,000; declining a
   holder who would have repaid forgoes US$500 of margin. That is the report's own 4 to 1 ratio, so its cutoff of 0.20
   is the right one if the scores are calibrated. Cost per 1,000 holders at 0.20, and at the cross-fitted cutoff: on
   each half, the cutoff that minimises cost on the other half, from 0.05 to 0.60 in steps of 0.005. Paired bootstrap of
   the cost difference on each evaluation half, the chosen cutoff held fixed. Sweep: ratios 2, 3, 4, 6 and 8 (the
   default cost held at US$2,000), each at its cost-optimal cutoff if calibrated, 1 / (1 + ratio), and at the
   cross-fitted one. Grade by F2.
10. **Data.** Counts of codes the data dictionary does not define, the share of repayment status 1 in each month,
    repeated financial profiles, negative bills. Grade: note, unless a check above measures an effect.
11. **Claims.** Every claim in the report with a number, and the claims of exclusion and determinism, is listed in
    `results/results.json` with its check and verdict; the page shows them.

### Predictions, written before the validation run

1. The validation AUC lies inside the report's interval (0.7757 to 0.8138).
2. The band 0.20 to 0.25 over-predicts: observed below mean predicted, with the interval excluding it (the report's
   fourth quintile, 22.28% predicted against 18.27% observed, sits there).
3. The stale feed lowers AUC by more than 0.03.
4. The youngest age group has the lowest approval rate, and its ratio is below 0.80.
5. The logistic challenger is within 0.01 AUC of the model.
6. At 4 to 1, the cross-fitted cutoff is above 0.20 and saves cost with an interval excluding zero in at least one
   half.

### What would change the conclusion

- A validation AUC or approved-default rate wholly worse than claimed would make the report's performance claims a
  blocking finding (B2) instead of a confirmation.
- If the bands next to the cutoff were calibrated, the cutoff finding (F1, F2) would go.
- The costs are assumptions: the sweep shows where the cutoff finding holds across ratios 2 to 8.
- One author, one run: a different author could build a model with different faults. The page says so on the first
  screen.
