Puncc
👋 Puncc is a python library for predictive uncertainty quantification using conformal prediction.
Install / Use
/learn @deel-ai/PunccREADME
Puncc (short for Predictive uncertainty calibration and conformalization) is an open-source Python library. It seamlessly integrates a collection of state-of-the-art conformal prediction algorithms and associated techniques for diverse machine learning tasks, including regression, classification, object detection and anomaly detection. Puncc can be used with any predictive model to provide rigorous uncertainty estimations. Under data exchangeability (or i.i.d), the generated prediction sets are guaranteed to cover the true outputs within a user-defined error $\alpha$.
Documentation is available online.
📚 Table of contents
- 🐾 Installation
- 📖 Documentation
- 👨🎓 Tutorials
- 🚀 QuickStart
- 📚 Citation
- 💻 Contributing
- 🙏 Acknowledgments
- 👨💻 Creators
- 📝 License
🐾 Installation
puncc requires a version of python higher than 3.8 and several libraries including Scikit-learn and Numpy. It is recommended to install puncc in a virtual environment to not mess with your system's dependencies.
You can directly install the library using pip:
pip install puncc
The package is also available on conda-forge:
conda install -c conda-forge puncc
📖 Documentation
For comprehensive documentation, we encourage you to visit the official documentation page.
<a id="-tutorials"></a>
👨🎓 Tutorials
We highly recommend following the introductory tutorials to get familiar with the library and its API.
| Tutorial | Description | Link |
|----------|-------------|------|
| Introduction Tutorial | Get started with the basics of puncc. |
|
| API Tutorial | Learn about puncc's API. |
|
| Tutorial on CP with PyTorch | Learn how to use puncc with PyTorch. |
|
|
Conformal Object Detection | Learn to conformalize an object detector. |
|
|
Conformal Text Classification | Learn to conformalize pretrained HuggingFace NLP model. |
|
|
Conformal Time Series Forecasting | Learn to conformalize time series models. |
|
| Architecture Overview | Detailed overview of puncc's architecture. |
|
🚀 Quickstart
Conformal prediction enables to transform point predictions into interval predictions with high probability of coverage. The figure below shows the result of applying the split conformal algorithm on a linear regressor.
<figure style="text-align:center"> <img src="docs/assets/cp_process.png"/> </figure>Many conformal prediction algorithms can easily be applied using puncc. The code snippet below shows the example of split conformal prediction with a pretrained linear model:
from deel.puncc.api.prediction import BasePredictor
from deel.puncc.regression import SplitCP
# Load calibration and test data
# ...
# Pretrained regression model
# trained_linear_model = ...
# Wrap the model to enable interoperability with different ML libraries
trained_predictor = BasePredictor(trained_linear_model)
# Instanciate the split conformal wrapper for the linear model.
# Train argument is set to False because we do not want to retrain the model
split_cp = SplitCP(trained_predictor, train=False)
# With a calibration dataset, compute (and store) nonconformity scores
split_cp.fit(X_calib=X_calib, y_calib=y_calib)
# Obtain the model's point prediction y_pred and prediction interval
# PI = [y_pred_lower, y_pred_upper] for a target coverage of 90% (1-alpha).
y_pred, y_pred_lower, y_pred_upper = split_cp.predict(X_test, alpha=0.1)
The library provides several metrics (deel.puncc.metrics) and plotting capabilities (deel.puncc.plotting) to evaluate and visualize the results of a conformal procedure. For a target error rate of $\alpha = 0.1$, the marginal coverage reached in this example on the test set is higher than $90$% (see Introduction tutorial):
More flexibility with the API
Puncc provides two ways of defining and using conformal prediction wrappers:
- A direct approach to run state-of-the-art conformal prediction procedures. This is what we used in the previous conformal regression example.
- Low-level API: a more flexible approach based of full customization of the prediction model, the choice of nonconformity scores and the split between fit and calibration datasets.
A quick comparison of both approaches is provided in the API tutorial for a regression problem.
<figure style="text-align:center"> <img src="docs/assets/puncc_architecture.png" width="100%"/> </figure>🖥️ Implemented Algorithms
<details open> <summary>Overview of Implemented Methods from the Literature:</summary>| Procedure Type | Procedure Name | Description (more details in Theory overview) |
|-----------------------------------------|------------------------------------------------------|-------------------------------------------------------|
| Conformal Regression | deel.puncc.regression.SplitCP | Split Conformal Regression |
| Conformal Regression | deel.puncc.regression.LocallyAdaptiveCP | Locally Adaptive Conformal Regression |
| Conformal Regression | deel.puncc.regression.CQR | Conformalized Quantile Regression |
| Conformal Regression | deel.puncc.regression.CvPlus | CV + (cross-validation) |
| Conformal Regression | deel.puncc.regression.EnbPI | Ensemble Batch Prediction Intervals method |
| Conformal Regression | [deel.puncc.regression.aEnbPI](https://deel-ai.github.io/puncc/regre
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
