Skip to main content

CLDD — closed-loop default detection

CI License: MIT Docs: Sphinx Python ≥3.10

Stress-test a probability-of-default (PD) model under selective labels — and get the severity at which it breaks. Real lending data only labels the loans a prior underwriter approved, so you cannot measure calibration on the applicants you declined — exactly where a new model must still be right. CLDD builds synthetic lending worlds with planted ground truth, hides labels the way real approval policies do, and grades every correction against that truth.

  • Deterministic — byte-identical per seed, scikit-learn-only, no services or GPUs.
  • Pluggable — correction levers (IPW, retrain, exploration, reject inference) are classes; add yours by subclassing Corrector.
  • Honest by construction — every results figure registered in the doc-number gate recomputes from a committed CSV in CI, and every artifact is pinned by content hash; the results and their limits are in docs/results.md.

What this is — and is not. CLDD is a validation harness graded against planted synthetic ground truth; it is not a credit-modeling toolkit. The correction levers it ships (IPW, retrain, exploration, reject inference) exist to be measured against a known answer — nothing in this repo is validated for making decisions on real borrower data.

Install

pip install closed-loop-default-detection

The import name is cldd. For development (tests, docs, the committed evidence), install from source:

git clone https://github.com/hossainpazooki/closed-loop-default-detection.git
cd closed-loop-default-detection
pip install -e ".[dev]"

Python ≥ 3.10; dependencies are ranges (numpy>=2.0, pandas>=2.2, scikit-learn>=1.6, scipy>=1.11, matplotlib>=3.8) so cldd sits alongside your stack. Exact pins for float-exact reproduction: requirements-dev.txt (details).

60-second tour

from cldd import SelectiveLabelsLoop

result = SelectiveLabelsLoop(improve_mode="both").run()   # "reweight" | "retrain" | "both"
print("Operating frontier:", result.frontier_severity)
for r in result.rounds:
    print(r.selection_severity, r.naive.declined_ece, r.passed)
flowchart TD
    A["<b>1. Generate</b><br/>synthetic cohort at a given selection severity<br/>plant true default, then hide it via the approval policy"]
    B["<b>2. Measure</b><br/>train the PD model on approved rows only,<br/>score it against planted truth on the declined subpopulation"]
    C["<b>3. Improve</b><br/>apply a correction lever:<br/>IPW reweight &middot; disjoint retrain &middot; exploration"]
    D{"Corrected declined-cohort<br/>ECE &le; target?"}
    E["<b>Operating frontier</b><br/>report the highest severity<br/>that still passes"]

    A --> B --> C --> D
    D -->|"yes &mdash; raise the severity"| A
    D -->|"no &mdash; stop"| E

A runnable end-to-end demo (classic + custom-lever paths) is examples/quickstart.py. Full mechanics, diagnostics, and the feedback simulation: docs/how-it-works.md.

Scope. CLDD is a synthetic validation harness, not a production pipeline: retraining and feedback are seeded simulations inside the harness; it never acts on live data or real lending decisions.

What's in the box

Everything is importable from top-level cldd (full reference: the Sphinx docs):

Import What it is
SelectiveLabelsLoop the closed loop; .run() → LoopResult (frontier + per-round metrics)
Corrector + NaiveCorrector, IPWReweightCorrector, DisjointRetrainCorrector, ExplorationCorrector the lever ABC and the four built-ins
ReclassificationCorrector, AugmentationCorrector, FuzzyAugmentationCorrector, ParcellingCorrector four classic reject-inference methods, graded against planted truth (honest results)
SyntheticBorrowerGenerator, StructuralBorrowerGenerator the flat and fitted-SCM synthetic worlds
run_counterfactual_eval, GComputationEstimator counterfactual validator (g-computation vs naive conditioning)
FeedbackLoop model-in-the-loop selective-labels simulation
empc_literature, emp_harness the two EMP variants — price the frontier in profit (reporting only, never loop control)
positivity_diagnostics observable regime/drift alarm — needs no declined-row labels
CalibratedPDClassifier the calibrated PD detector as a scikit-learn estimator
cldd.fidelity.run_fidelity_gate SCM-vs-real marginal-fidelity gate (univariate marginals only)

Add a lever by subclassing Corrector (name, control_priority, apply) and passing correctors=[NaiveCorrector(), MyCorrector()] — the legacy improve_mode API is unchanged and byte-identical. Contract details: CONTRIBUTING.md.

Use the detector from sklearn tooling — CalibratedPDClassifier is a thin, tested wrapper (binary-only; NaN features OK; the full check_estimator battery passes with zero failed checks on scikit-learn 1.7.2–1.9.0; probabilities byte-identical to the research API):

from sklearn.model_selection import cross_val_score
from cldd import CalibratedPDClassifier

scores = cross_val_score(CalibratedPDClassifier(random_state=42), X, y, scoring="neg_brier_score")

Command-line drivers

Each driver runs without install (adds src/ to the path) and writes to artifacts/:

python scripts/run_loop.py                    # the closed loop → frontier table + plot (--generator scm for the SCM world)
python scripts/run_frontier_sweep.py --quick  # frontier distribution across the 25-seed set (drop --quick for all)
python scripts/run_seed_sweep.py --quick      # counterfactual certification (drop --quick for all seeds)
python scripts/run_reject_inference.py        # reject-inference levers vs the frontier
python scripts/run_exploration_sweep.py       # frontier vs exploration budget
python scripts/run_feedback.py                # model-in-the-loop feedback simulation
python scripts/paired_significance.py         # recompute the headline stat from committed CSVs

Validation

pytest, all synthetic, no real data needed. CI runs a pinned-repro job (exact pins), a cross-version/OS compat matrix, and a strict docs build; a doc-number gate recomputes every registered figure in the docs from a committed artifact. A few float-sensitive tests reproduce only under the pins in requirements-dev.txt; the optional marginal-fidelity gate compares the SCM against a private real dataset via CLDD_DATA_DIR and is the only thing that needs it. Details, reproducibility, and troubleshooting: docs/validation.md.

Documentation

Where What
docs/results.md every measured result — the frontier and its distribution, the v4 intervention, the two pre-registered experiments, the two pricing layers
docs/quickstart.md run the loop, the counterfactual eval, the fidelity report
docs/how-it-works.md loop mechanics, diagnostics, feedback simulation, repo map
docs/configuration.md every knob (config.py) and the one env var
docs/validation.md tests, gates, reproducibility, troubleshooting
docs/reject_inference.md the four RI methods and their honest (modest) results
docs/assessment.md the accompanying article — independent results & methodology assessment (dated snapshot)

Build locally: pip install -e ".[docs]" && sphinx-build -b html -W docs docs/_build/html.

Status

Alpha, on PyPI; version history in CHANGELOG.md.

CLDD began as a validation harness for the Intuit TechWeek SMB Underwriting Challenge; it is not a submission and does not alter challenge files.

Citation

Metadata in CITATION.cff (GitHub's "Cite this repository" reads it):

@software{pazooki_cldd_2026,
  author  = {Pazooki, Hossain},
  title   = {{closed-loop-default-detection}: measuring selective-labels default
             detection and the PD model's operating frontier},
  year    = {2026},
  version = {0.4.0},
  license = {MIT},
  url     = {https://github.com/hossainpazooki/closed-loop-default-detection}
}

Metadata

Release files for closed-loop-default-detection 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for closed-loop-default-detection 0.4.0
File Size Uploaded Provenance Actions
closed_loop_default_detection-0.4.0.tar.gz 141.8 kB With provenance Details for closed_loop_default_detection-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for closed-loop-default-detection 0.4.0
File Interpreter ABI Platform Actions
closed_loop_default_detection-0.4.0-py3-none-any.whl Python 3 none any Details for closed_loop_default_detection-0.4.0-py3-none-any.whl

Total release size: 220.1 kB

Release files / closed_loop_default_detection-0.4.0.tar.gz

Download URL closed_loop_default_detection-0.4.0.tar.gz
Size 141.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c9ad131d3e81f14e62194f9a0b631667e4f315528581fde1b78f764461ad2ff0
BLAKE2b-256 checksum
How to use checksums
f849ccbe952befc6109838b879202ca0d1ab91991c292baf644141ac4a956eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / closed_loop_default_detection-0.4.0-py3-none-any.whl

Download URL closed_loop_default_detection-0.4.0-py3-none-any.whl
Size 78.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
168eacf9e4bbcc59308194f3b430388dd13c61b31959e0457cafaa6b869b8556
BLAKE2b-256 checksum
How to use checksums
7026b0672bd09008db612eb7fbe5a6ed0ccb4e4b7e155b9e0a0d6a5006882768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for closed-loop-default-detection 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for closed_loop_default_detection-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page