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 --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.2.tar.gz (10.8 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.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tinycp-0.0.2.tar.gz
  • Upload date:
  • Size: 10.8 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.2.tar.gz
Algorithm Hash digest
SHA256 d082d9cd87ec8856c26655a9f2679e063cf22b34b2c8cc22c630f272ea240e70
MD5 db5bc00a26fbd665440f27d1b0c7f748
BLAKE2b-256 d48f4a0e5b33f97e1d86530294e8a2606595c4a7c4aa276dafb2c6bc1af3ff4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tinycp-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6589eaeffd44616e12e606875ad9872321a0990fff6af8a50e7980266694574
MD5 027f70cc5442617d541d4dc0e19f375c
BLAKE2b-256 af7c364e7eec386e55ed69abbd41ed9432cbf586db625a0e0fe69a2cb9b2438e

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