Approximate full Conformal Prediction
This repository contains the Python implementation of Approximating Full Conformal Prediction at Scale via Influence Functions.
Overview
Approximate full Conformal Prediction (ACP) outputs a prediction set that contains the true label with at least a probability specified by the practicioner. In large datasets, ACP inherits the statistical power of the highly efficient full Conformal Prediction. The method works as a wrapper for any differentiable ML model.
Contents
This repository is organized as follows. In the folder src/acp you can find the following modules:
methods.pyPython implementation of the ACP algorithms.others.pyPython implementation of the comparing methods (SCP, APS, RAPS, CV+, JK+).wrapper.pyPython implementation of ACP as a wrapper for any differentiable PyTorch model. Seemodels.pyfor examples.models.pyExamples of models compatible withwrapper.py(e.g., logistic regression, neural network, convolutional neural network).experiments.pyPython file to run the experiments from the command line.models/Saved models.
The folder src/third_party/ contains additional third-party software.
Third-party software
We include the following third-party packages for comparison with ACP:
Usage
Installation
ACP can be utilized as a fully-independent pip package. You can download the framework by running the following command in the terminal:
pip install approx-cp
In order to use ACP in your own models, just include the following imports in your file:
from acp.wrapper import ACP_D, ACP_O #Deleted scheme (ACP_D) and ordinary scheme (ACP_O)
Alternatively, you can clone this repo by running:
git clone https://github.com/cambridge-mlg/acp
cd acp
And install the ACP Python package in a customizable conda environment:
conda create -n myenv python=3.9
conda activate myenv
pip install --upgrade pip
pip install -e .
Now, just include the import:
from acp.wrapper import ACP_D, ACP_O
Constructing prediction sets with ACP
ACP works as a wrapper for any PyTorch model with .fit() and .predict() methods. Once you instantiate your model, you can generate tight prediction sets that contain the true label with a specified probability. Here is an example with synthetic data:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from acp.models import NeuralNetwork
from acp.wrapper import ACP_D
X, Y = make_classification(n_samples = 1100, n_features = 10, n_classes = 2, n_clusters_per_class = 1, n_informative = 3, random_state = 42)
Xtrain, Xtest, Ytrain, Ytest = train_test_split(X, Y, test_size = 100, random_state = 42)
model = NeuralNetwork(input_size = 10, num_neurons = [20, 10], out_size = 2, seed = 42, l2_reg = 0.01)
ACP = ACP_D(Xtrain, Ytrain, model, seed = 42, verbose = True)
sets = ACP.predict(Xtest, epsilon = 0.1, out_file = "results/test")
Reference
J. Abad Martinez, U. Bhatt, A. Weller and G. Cherubin. Approximating Full Conformal Prediction at Scale via Influence Functions. Association for the Advancement of Artificial Intelligence Conference on Artificial Intelligence (AAAI), 2023.
BiBTeX:
@inproceedings{Abad2023ApproximatingFC,
title={Approximating Full Conformal Prediction at Scale via Influence Functions},
author={Javier Abad and Umang Bhatt and Adrian Weller and Giovanni Cherubin},
booktitle={AAAI Conference on Artificial Intelligence},
year={2023}
}
Metadata
Release files for approx-cp 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| approx-cp-0.0.2.tar.gz | 24.4 kB | Without provenance | Details for approx-cp-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| approx_cp-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for approx_cp-0.0.2-py3-none-any.whl |
Total release size: 50.0 kB
Release files / approx-cp-0.0.2.tar.gz
| Download URL | approx-cp-0.0.2.tar.gz |
|---|---|
| Size | 24.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4a9754a481271a661c9adcccd772b00f4474a615e1f58d46dc7ec0717709064
|
|
BLAKE2b-256 checksum How to use checksums |
50fe0e880914ea77eba609899488db9b5755effca40b31ebfba327dd620d214e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / approx_cp-0.0.2-py3-none-any.whl
| Download URL | approx_cp-0.0.2-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d43940f641b9dea51f79ffc258c3d3a9084f7125b867705620bf4eb391648c88
|
|
BLAKE2b-256 checksum How to use checksums |
24f69a0136066fac52af1f6034af9481180d61596addfc4cde61ac52b6fda9a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for approx-cp 0.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.