Skip to main content

A small toolbox for conformal prediction

Project description

TinyCP

TinyCP is an experimental Python library for conformal predictions, providing tools to generate valid prediction sets with a specified significance level (alpha). This project aims to facilitate the implementation of personal and future projects on the topic.

For more information on a previous project related to Out-of-Bag (OOB) solutions, visit this link.

Currently, TinyCP supports Out-of-Bag (OOB) solutions for RandomForestClassifier in binary classification problems. For more options and advanced features, consider exploring Crepes.

Installation

Install TinyCP using pip:

pip install tinycp

Note: If you want to enable plotting capabilities, you need to install the extras using Poetry:

poetry install --all-extras

Usage

Importing Classes

Import the conformal classifiers from the tinycp.classifier module:

from tinycp.classifier.class_conditional import OOBBinaryClassConditionalConformalClassifier
from tinycp.classifier.marginal import OOBBinaryMarginalConformalClassifier

Example

Example usage of OOBBinaryClassConditionalConformalClassifier:

from sklearn.ensemble import RandomForestClassifier
from tinycp.classifier.class_conditional import OOBBinaryClassConditionalConformalClassifier

# Create and fit a RandomForestClassifier
learner = RandomForestClassifier(n_estimators=100, oob_score=True)
X_train, y_train = ...  # your training data
learner.fit(X_train, y_train)

# Create and fit the conformal classifier
conformal_classifier = OOBBinaryClassConditionalConformalClassifier(learner)
conformal_classifier.fit(y_train)

# Make predictions
X_test = ...  # your test data
predictions = conformal_classifier.predict(X_test)

Evaluating the Classifier

Evaluate the performance of the conformal classifier using the evaluate method:

results = conformal_classifier.evaluate(X_test, y_test)
print(results)

Classes

BaseConformalClassifier

BaseConformalClassifier is a base class for conformal prediction using a RandomForestClassifier and Venn-Abers calibration for confidence estimation.

OOBBinaryClassConditionalConformalClassifier

OOBBinaryClassConditionalConformalClassifier is a class conditional conformal classifier based on OOB methodology, using a random forest classifier as the learner.

OOBBinaryMarginalConformalClassifier

OOBBinaryMarginalConformalClassifier is a conformal classifier based on OOB predictions, using RandomForestClassifier and Venn-Abers calibration.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinycp-0.0.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinycp-0.0.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file tinycp-0.0.1.tar.gz.

File metadata

  • Download URL: tinycp-0.0.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for tinycp-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f47a9c547b349f5e176503bf5b5e837d543686829d10089a4d1884a391b2b344
MD5 c2e7847e2f6a6c7e44d14f4f1c5a58f0
BLAKE2b-256 1b88e594ba9fd69f208c538454e1dfd989c389e57741b622130dcd974396801c

See more details on using hashes here.

File details

Details for the file tinycp-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tinycp-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for tinycp-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa701188b6e2e12cc97570459988af69367b52fc0a48c9db8715543472c15fe
MD5 8fbb4bec0b139f6d8d94725b443ef6f7
BLAKE2b-256 f20190954bdd2265e26a5015c6ea8f36cd0f3b57bc48dc50dc10f4bc9ca5d6cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page