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.

Changes about previous work

  • calibrate: instead of Balanced Accuracy Score, it can be calibrated either Matthews Correlation Coefficient or Bookmaker Informedness Score, for better reliability
  • evaluate: scores bm and mcc for more reliability

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 --E plot

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.3.tar.gz (1.8 MB 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.3-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tinycp-0.0.3.tar.gz
Algorithm Hash digest
SHA256 13e0b9fc8157cf6c680c4e50e935ba48d414f8dc297cd054e77ee68e05dcba0a
MD5 768484591f401b8bc6056f9109205b16
BLAKE2b-256 156c8281a43d7c52c4fed91bb1943a55e893f610f5e1fb9be68892c98d39d843

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tinycp-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 1.8 MB
  • 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9f177dd4c22dc750cf75206d9c18c374b5d13f57bfbd9b63a623a58b1a1b9353
MD5 5dd71136bb7ba108f37c7f7af0e26067
BLAKE2b-256 695faf06f2c0d4be8deb84f99c62fecc085dc48a3f5aab93f0dd7ef26cd7ca8f

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