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, as well as RandomForestRegressor and RandomForestQuantileRegressor for regression tasks. For additional options and advanced features, you may want to explore 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 Classifiers

Import the conformal classifiers from the tinycp.classifier module:

from tinycp.classifier import BinaryClassConditionalConformalClassifier
from tinycp.classifier import BinaryMarginalConformalClassifier

Importing Regressors

Import the conformal regressors from the tinycp.regressor module:

from tinycp.regressor import ConformalizedRegressor
from tinycp.regressor import ConformalizedQuantileRegressor

Example

Example usage of BinaryClassConditionalConformalClassifier:

from sklearn.ensemble import RandomForestClassifier
from tinycp.classifier import BinaryClassConditionalConformalClassifier

# 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 = BinaryClassConditionalConformalClassifier(learner)
conformal_classifier.fit(y=y_train, oob=True)

# 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

BinaryMarginalConformalClassifier

BinaryMarginalConformalClassifier A marginal coverage conformal classifier methodology utilizing a classifier as the underlying learner. This classifier supports the option to use Out-of-Bag (OOB) samples for calibration.

BinaryClassConditionalConformalClassifier

BinaryClassConditionalConformalClassifier A class conditional conformal classifier methodology utilizing a classifier as the underlying learner. This classifier supports the option to use Out-of-Bag (OOB) samples for calibration.

ConformalizedRegressor

ConformalizedRegressor A conformal regressor methodology utilizing a regressor as the underlying learner. This regressor supports the option to use Out-of-Bag (OOB) samples for calibration, providing valid prediction intervals for regression tasks.

ConformalizedQuantileRegressor

ConformalizedQuantileRegressor A conformal quantile regressor methodology utilizing a quantile regressor as the underlying learner. This regressor supports the option to use Out-of-Bag (OOB) samples for calibration, offering more robust prediction intervals by leveraging quantile estimates.

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.71.tar.gz (14.0 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.71-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tinycp-0.0.71.tar.gz
Algorithm Hash digest
SHA256 f5dd76224a539f608b570826706ba9fc75970836aeaa4fc8ebebb3743d9de528
MD5 9fab1949abf6327f6f5dd019b6d60513
BLAKE2b-256 2243889df650bd9b44dbe57f482ac3711432523d28d1fdd576c366fe7bca5347

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tinycp-0.0.71-py3-none-any.whl
Algorithm Hash digest
SHA256 b4ca8ef0acd4d3bb9a504abce958f2b1acb5ef7d4a5c17680b35911a0c4e673e
MD5 b99991d90dd5b3e8b119d2be47490ed5
BLAKE2b-256 024f6c9a3bc24f953fbafa83344d46af4d6b1b5967611a98f6a873a01702299a

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