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.4.tar.gz (11.1 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.4-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tinycp-0.0.4.tar.gz
  • Upload date:
  • Size: 11.1 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.4.tar.gz
Algorithm Hash digest
SHA256 f0cd019e08fb0c1f573cb914ad36cdc4058a9dd78c63bc5221cf23a8fdfff9f4
MD5 cd7f07228ee39249cb08a81d7cf0e406
BLAKE2b-256 999ed59e3c06f58272f5017529359b72d183bca2c9dc25255f27cf353d256e7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tinycp-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 278ca256c4937f411c146d060beb4b40bc5990486251c2522d0da892ce186c39
MD5 3f8d302c7e3e694092680beb93d3b447
BLAKE2b-256 78c834e6763043d165709947ebd5abe7e6edeff679acc7017e316b3d4566a120

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