Skip to main content

dracp — Dynamic Regime-Aware Conformal Prediction

tests License: MIT DOI PyPI

Distribution-free prediction intervals for forecasting when several distribution shifts act at the same time — covariate shift, concept drift, local heterogeneity and latent regimes.

Classical conformal prediction guarantees finite-sample coverage under exchangeability, which sequential economic data routinely violate. Existing adaptive extensions each correct a single departure. DRACP composes four mechanisms inside one weighted-conformal calibration step:

  • density-ratio weighting — corrects a shifted covariate distribution;
  • localized kernel weighting — restores approximate conditional validity, with an automatic floor on the effective sample size;
  • regime-aware weighting — up-weights calibration points from the same latent regime as the query;
  • self-tuning online control — adapts the significance level from realised coverage, aggregating adaptive-conformal experts over several learning rates.

It wraps any point-prediction model: conformal validity does not depend on the model, so keep whatever forecaster you already trust.

Install

pip install dracp

or from source:

git clone https://github.com/bogdanoancea/dracp.git
cd dracp
pip install -e .

Requires Python ≥ 3.10 and the standard scientific stack (NumPy, pandas, SciPy, scikit-learn). Reproducing the paper's experiments additionally needs pip install -e ".[experiments]".

Quick start

import numpy as np, pandas as pd
from sklearn.ensemble import RandomForestRegressor
from dracp import ConformalForecaster

# X, y in chronological order
cf = ConformalForecaster(
        model=RandomForestRegressor(n_estimators=200, random_state=0),
        alpha=0.10)                       # nominal coverage 90%
cf.fit(X_train, y_train)

# Sequential intervals: outcomes are revealed one step at a time,
# so calibration adapts online (recommended for forecasting).
lower, upper = cf.predict_interval(X_test, y_test)

print(cf.score(X_test, y_test))           # coverage, mean width, interval score
cf.predict_frame(X_test, y_test).head()   # tidy DataFrame

Omit y in predict_interval for fixed (non-adaptive) calibration. A complete runnable script is in example_usage.py.

Useful options

Any configuration field can be passed as a keyword argument:

ConformalForecaster(model=..., alpha=0.1,
                    calibration_window=500,   # rolling calibration buffer
                    n_regimes=3,              # latent regimes
                    bandwidth=2.0,            # localization kernel
                    use_faci_control=True,    # self-tuning controller (default)
                    asymmetric=True)          # two-sided quantiles for skewed errors

Baselines included

For benchmarking, the package also implements split, rolling and adaptive (ACI) conformal prediction, and the recent FACI, SAOCP and conformal PID online procedures, all behind the same interface.

Reproducing the paper

The repository ships the full experimental pipeline. Raw data and results are not version-controlled; a single command downloads everything and regenerates every table and figure:

macOS / Linux

chmod +x run.sh
SEEDS=20 ./run.sh          # all stages
./run.sh setup real        # or selected stages

Windows (PowerShell or Command Prompt)

run.bat
run.bat setup real

Any platform, directly:

python run.py                    # all stages
python run.py montecarlo report  # selected stages

The pipeline is implemented once, in run.py; run.sh and run.bat are thin wrappers, so behaviour is identical everywhere. Stages are setup, synthetic, real, sweeps, montecarlo, report. Settings are environment variables (SEEDS, SKIP_DOWNLOADS, NO_ONLINE, RUN_TESTS, MAX_ELECTRICITY_ROWS, INFLATION_GEO, PYTHON_BIN); on Windows set them with set SEEDS=20 (cmd) or $env:SEEDS=20 (PowerShell).

The script creates its own virtual environment and calls that interpreter explicitly, so it does not require a python on your PATH (macOS ships only python3). Include the setup stage whenever the environment is missing; a .venv left behind by an interrupted install is detected and rebuilt. Override the interpreter with PYTHON_BIN=python3.11 ./run.sh if needed.

The report stage writes the paper's tables and figures to results/paper/:

python -m reporting.paper_outputs --results-root results --out results/paper

Hyperparameter-sensitivity sweeps (the sensitivity appendix) are produced by

python -m experiments.sensitivity        # resumable; writes results/sweeps_all.csv

The paper-output step regenerates every table body (results/paper/tables/*.tex, ready to \input) and figure (results/paper/figures/*.pdf) reported in the paper, together with key_statistics.json containing the headline numbers (average ranks, win counts, Friedman/Nemenyi statistics, Diebold--Mariano tallies).

Data sources are public: Eurostat (EU-27 HICP inflation), FRED (US macroeconomic and financial series) and UCI (electricity demand).

Citing

If you use this software, please cite the archived release and the paper.

Software (DOI: 10.5281/zenodo.21675706):

@software{oancea_dracp_2026,
  author    = {Oancea, Bogdan},
  title     = {dracp: Dynamic Regime-Aware Conformal Prediction},
  year      = {2026},
  publisher = {Zenodo},
  version   = {v0.1.0},
  doi       = {10.5281/zenodo.21675706},
  url       = {https://doi.org/10.5281/zenodo.21675706}
}

Paper:

Oancea, B. (2026). Dynamic Regime-Aware Conformal Prediction for Economic Forecasting under Multiple Distribution Shifts.

GitHub also renders a "Cite this repository" button from CITATION.cff.

License

MIT — see LICENSE.

Metadata

Release files for dracp 0.2.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 dracp 0.2.0
File Size Uploaded
dracp-0.2.0.tar.gz 31.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dracp 0.2.0
File Interpreter ABI Platform
dracp-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.2 kB

Release files / dracp-0.2.0.tar.gz

Download URL dracp-0.2.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
25bfd7460de41105aff06cb46570d146cc350048fa7cdc5c0a7138310f38202f
BLAKE2b-256 checksum
How to use checksums
bd72adea3d740d7f0aa0a839bd31b0650d21e6b468d58cdcd21e8b354003b9db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / dracp-0.2.0-py3-none-any.whl

Download URL dracp-0.2.0-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9727b9c6fc6c828c6cec393b8b9aa81af9378789ed68fdb6edf093b50eaa7f63
BLAKE2b-256 checksum
How to use checksums
56bda90ff526aa132436e47cc9acaedec2f88da845005343b56d5ab8eebd90e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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