yromano/cqr

Conformalized Quantile Regression

What it solves

When a data-driven system makes predictions, decision makers need to know how much they can trust those predictions. A prediction interval — a range of likely outcomes — is a natural way to express that uncertainty. But many interval-building methods rely on strong assumptions about the data's distribution, which may not hold in practice. This package provides methods that construct prediction intervals with rigorous coverage guarantees that stay valid in finite samples and do not depend on distributional assumptions.

How it works

The package implements two related methodologies:

  • Conformalized Quantile Regression (CQR) combines quantile regression (which estimates the conditional quantiles of the target variable) with conformal prediction (which wraps around any predictive model to produce intervals with guaranteed coverage). CQR works as a wrapper around any quantile regression algorithm, such as random forests or neural networks, and then adjusts the intervals to ensure the miscoverage rate is controlled regardless of the underlying model.

  • Equalized coverage extends the same idea to ensure fairness across protected groups. It forces the prediction intervals to have equal coverage for all groups of interest, providing distribution-free, finite-sample guarantees while remaining a wrapper around any predictive algorithm.

Both methods are implemented in Python and rely on standard scientific libraries (numpy, scipy, scikit-learn, scikit-garden, pytorch, pandas). The repository includes demonstration notebooks and reproducible experimental code that replicate the results from the two foundational papers.

Who it's for

Researchers, data scientists, and engineers who build prediction systems and need to communicate uncertainty to stakeholders, especially in applications where fairness across groups is a concern. It is also valuable for anyone studying conformal inference or quantile regression methods.

Highlights

  • Implements two statistically rigorous methods (CQR and equalized coverage) that provide distribution-free, finite-sample coverage guarantees.
  • Wrapper design allows easy integration with any quantile regression model, including random forests and neural networks.
  • Includes reproducible experiments and Jupyter notebooks demonstrating usage on real and synthetic datasets.
  • Self-contained Python package with minimal dependencies, and code partially adapted from the well-known nonconformist package.

Related

  • Project
  • Project
  • Project
  • Project