Skip to main content

conforma

Know when to trust your model's predictions.

PyPI version Python 3.12+ NumPy only MIT License


Conformal prediction is a technique for getting honest uncertainty estimates from trained ML models. conforma is a lightweight, framework-agnostic Python library that makes it easy to apply. Give it a held-out calibration set and it will wrap your model to produce prediction sets (for classifiers) or prediction intervals (for regressors) with real statistical guarantees. No changes to your model, no retraining, and only numpy as a dependency.

Installation

python -m pip install conforma

Quick start

from conforma import calibrate_classifier, ConformalClassifier

# 1. Get your model's predicted probabilities on a held-out calibration set
cal_probs = model.predict_proba(X_cal)  # shape: (n_examples, n_classes)

# 2. Calibrate
calibration = calibrate_classifier(cal_probs, y_cal)

# 3. Wrap your model
wrapper = ConformalClassifier(
    predict_fn=model.predict_proba,
    calibration=calibration,
)

# 4. Predict with guaranteed coverage
prediction_sets = wrapper.predict(X_test, coverage=0.90)
# >>> array([[ True, False, False],
#            [ True,  True, False]])

Each row is a prediction set where True marks a plausible class. A single True means the model is confident. Multiple True values mean it is uncertain. The guarantee is that at least 90% of prediction sets will contain the correct class.

You can also get the underlying p-values for each class directly.

p_values = wrapper.predict_p_values(X_test)
# >>> array([[0.92, 0.31, 0.04],
#            [0.87, 0.79, 0.11]])

Each value is a conformal p-value measuring how plausible that class is. Higher means the model was less surprised. A class enters the prediction set at coverage level c when its p-value is at least 1 - c. This is useful when you want to rank classes by plausibility, or apply different coverage thresholds after the fact without re-running the model.

FAQ

What is conformal prediction? A way to turn any model's outputs into prediction sets (for classifiers) or prediction intervals (for regressors) that come with a coverage guarantee: the true answer will be included at least X% of the time. It doesn't change the model. It just adds a calibration step after training.

Does this work with my model? If your model can produce per-class scores (probabilities, logits, etc.) for classification or numeric predictions for regression, yes. It doesn't matter what framework you trained with.

How much calibration data do I need? More calibration data means tighter prediction sets. A few hundred examples is a reasonable starting point, but even 50 can be useful. The library will raise an error if your calibration set is too small for your requested coverage level.

What's the catch? The guarantee relies on one assumption: calibration data and test data are drawn from the same distribution. If the world changes after calibration (new user behaviour, different sensor, etc.), you should recalibrate.

Is this really guaranteed? Where's the proof? Yes. The coverage guarantee is proven. The original proof comes from Vovk, Gammerman, and Shafer in Algorithmic Learning in a Random World (2005). If you want something shorter, Shafer and Vovk also wrote "A Tutorial on Conformal Prediction" (2008) in the Journal of Machine Learning Research. Fair warning, neither is light reading. For a more practical introduction, Angelopoulos and Bates wrote "A Gentle Introduction to Conformal Prediction and Distribution-Free Uncertainty Quantification" (2022), which is an easier read.

Documentation

Metadata

Release files for conforma 1.0.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 conforma 1.0.0
File Size Uploaded Provenance Actions
conforma-1.0.0.tar.gz 14.2 kB With provenance Details for conforma-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 34.0 kB

Release files / conforma-1.0.0.tar.gz

Download URL conforma-1.0.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
57ea9e03589635f829187089480a30e60e8f0e69d0bd07ef882285a2ad53924e
BLAKE2b-256 checksum
How to use checksums
57a8a6f7a3239f7a236f8b28f75d45796cd2b0141038d1bd91c8b2bcbde1549a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 May 21, 2026.

Transparency log

Release files / conforma-1.0.0-py3-none-any.whl

Download URL conforma-1.0.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac62c5b510757156589cc78bfb06d2d3e39d26b9deb1749d2af4df38f383b665
BLAKE2b-256 checksum
How to use checksums
0e8317111daafd3805fe7709a6ed092ccd9a9673c4a4b6bd3541074ef7c6d1ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 May 21, 2026.

Transparency log

Security for conforma 1.0.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 conforma-1.0.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 May 21, 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