Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joneswack/conformal-predictions-from-scratch

Various Conformal Prediction methods implemented from scratch in pure NumPy for an educational purpose.
https://github.com/joneswack/conformal-predictions-from-scratch

conformal-prediction machine-learning numpy python uncertainty-estimation

Last synced: about 2 months ago
JSON representation

Various Conformal Prediction methods implemented from scratch in pure NumPy for an educational purpose.

Awesome Lists containing this project

README

        

# Conformal Predictions from Scratch

The aim of this repository is to implement some popular Conformal Prediction methods from scratch using pure [NumPy](https://numpy.org/). The correctness is then verified with reference implementations from libraries like [MAPIE](https://mapie.readthedocs.io/en/stable/). All of this is done with illustrative examples and thorough explanation of the code.

Why do we reimplement things from scratch? Because we want to understand the methods from ground up in order to use them with confidence in future projects where stakes may be high. This understanding is also needed for researchers who may think about coming up with novel methods on their own. Therefore, the purpose of this repository is educational.

## 🕵️‍♀️ What are Conformal Predictions?

Conformal Predictions have become a very popular way of equipping machine learning models with predictive uncertainty estimates. One reason for this is that they are model-agnostic meaning that previously trained (or even deployed) models can be enhanced with predictive uncertainties post hoc. Another advantage is that Conformal Predictions come with theoretical guarantees on how much of the future data to be predicted will actually fall inside the predictive bands (generally assuming exchangeability of the data). This may seem to good to be true, but makes a lot of sense when understanding how the predictions are "conformalized".

A great list of references and tutorials on the topic can be found [here](https://github.com/valeman/awesome-conformal-prediction).

## 📝 The Structure of this Repository

The repository contains one Jupyter notebook per conformal prediction method, i.e., one way to obtain predictive error bands. All notebooks are located in the *notebooks* folder and new notebooks will be added over time.

### 📈 Regression

| Notebook Title (Method Name) | Description | Academic Reference | Reference Implementation |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| [Split Conformal Prediction](https://github.com/joneswack/conformal-predictions-from-scratch/blob/main/notebooks/regression/1-Split-Conformal-Prediction.ipynb) | Conformal Predictions with fixed prediction bands obtained via (the default) absolute residual scores. | [Distribution-Free Predictive Inference for Regression (Section 2.2)](https://arxiv.org/pdf/1604.04173.pdf) | [MAPIE Regressor with AbsoluteConformityScore](https://mapie.readthedocs.io/en/latest/generated/mapie.regression.MapieRegressor.html) |
| [Locally Weighted Conformal Prediction](https://github.com/joneswack/conformal-predictions-from-scratch/blob/main/notebooks/regression/2-Locally-Weighted-Conformal-Prediction.ipynb) | Conformal Predictions with variable prediction bands obtained via residual normalised scores. | [Distribution-Free Predictive Inference for Regression (Section 5.2)](https://arxiv.org/pdf/1604.04173.pdf) | [MAPIE Regressor with ResidualNormalisedScore](https://mapie.readthedocs.io/en/latest/generated/mapie.regression.MapieRegressor.html) |
| [Conformalized Quantile Regression (CQR)](https://github.com/joneswack/conformal-predictions-from-scratch/blob/main/notebooks/regression/3-Conformalised-Quantile-Regression.ipynb) | Conformal Predictions with variable prediction bands obtained via quantile regression. | [Conformalized Quantile Regression](https://proceedings.neurips.cc/paper_files/paper/2019/file/5103c3584b063c431bd1268e9b5e76fb-Paper.pdf) | [MAPIE QuantileRegressor](https://mapie.readthedocs.io/en/latest/generated/mapie.regression.MapieQuantileRegressor.html) |
| [Conformal Prediction Beyond Exchangeability](https://github.com/joneswack/conformal-predictions-from-scratch/blob/main/notebooks/regression/4-Conformal-Prediction-Beyond-Exchangeability.ipynb) | Analysis of Conformal Predictions when the exchangeability assumption is violated. | [Conformal prediction beyond exchangeability](https://arxiv.org/abs/2202.13415) | [Paper Code ZIP-File](https://rinafb.github.io/code/nonexchangeable_conformal.zip) |