A lightweight conformal prediction library built on top of scikit-learn.
Project description
Conformal Prediction Framework
Conformal Prediction Framework is a modular and extensible implementation of Conformal Predictors for classification problems. It is compatible with any model that follows the scikit-learn interface (fit, predict, predict_proba) and provides prediction sets with finite-sample statistical guarantees.
This framework allows practitioners to control the error rate of predictions under minimal assumptions and provides functionality for evaluating both coverage and prediction set size.
Installation
Install via pip:
pip install conformal-prediction-framework
Usage Example
import numpy as np
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from conformal_prediction_framework import ConformalClassifier, Model
# Step 1: Generate synthetic data
X, y = make_classification(
n_samples=1000,
n_features=20,
n_classes=3,
n_informative=10,
random_state=42
)
# Step 2: Split into training, calibration, and test sets
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.4, random_state=42)
X_calib, X_test, y_calib, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)
# Step 3: Wrap your classifier and create the conformal predictor
base_model = LogisticRegression(multi_class='multinomial', max_iter=1000)
model = Model(base_model)
conformal = ConformalClassifier(model=model, alpha=0.1)
# Step 4: Train and calibrate
conformal.fit(X_train, y_train)
conformal.get_nonconformity_scores(X_calib, y_calib)
conformal.calibrate_quantile()
# Step 5: Predict and evaluate
prediction_sets = conformal.get_prediction_sets(X_test)
coverage = conformal.evaluate_coverage(X_test, y_test)
avg_set_size = conformal.evaluate_average_set_size(X_test)
point_predictions = conformal.predict(X_test)
# Output results
print(f"Coverage: {coverage:.3f}")
print(f"Average prediction set size: {avg_set_size:.2f}")
print(f"Sample prediction sets: {prediction_sets[:5]}")
print(f"Point predictions: {point_predictions[:5]}")
Features
- Wraps any scikit-learn-like classifier.
- Provides conformal prediction sets with guaranteed coverage.
- Computes empirical coverage and average prediction set size.
- Modular design for extensibility.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conformal_prediction_framework-0.1.1.tar.gz.
File metadata
- Download URL: conformal_prediction_framework-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a19b4e930761ba7881d9710e5579a8de2b64c736de66d45db6e2f0aced11cdcb
|
|
| MD5 |
04bd4c174cc2cd5714a4e72185ed1037
|
|
| BLAKE2b-256 |
d4cc87d24a2a3718cd6f2690d4bcf51561e971b30d09db7ff6adcb1d95ff6c43
|
File details
Details for the file conformal_prediction_framework-0.1.1-py3-none-any.whl.
File metadata
- Download URL: conformal_prediction_framework-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1081da554bfb3ad02915f60e65468eab53c29f473fb12fe6bb90c2d71656b56c
|
|
| MD5 |
76c918d013c5ed176886b27802a7e775
|
|
| BLAKE2b-256 |
63b51ee9cdb39a49c06930b3a12a93a078139decd371b14f39130961ab9992de
|