tinycp


Nametinycp JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryA small toolbox for conformal prediction
upload_time2025-01-19 03:01:40
maintainerNone
docs_urlNone
authorLucas Leão
requires_python<4.0,>=3.10
licenseMIT
keywords machine-learning conformal-prediction
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/HeyLucasLeao/cp-study).

## 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](https://github.com/henrikbostrom/crepes).

## Installation

Install TinyCP using pip:

```bash
pip install tinycp
```

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

```bash
poetry install --E plot
```

## Usage

### Importing Classes

Import the conformal classifiers from the `tinycp.classifier` module:

```python
from tinycp.classifier.class_conditional import BinaryClassConditionalConformalClassifier
from tinycp.classifier.marginal import BinaryMarginalConformalClassifier
```

### Example

Example usage of `BinaryClassConditionalConformalClassifier`:

```python
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 = 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:

```python
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.

## License

This project is licensed under the MIT License.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tinycp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "machine-learning, conformal-prediction",
    "author": "Lucas Le\u00e3o",
    "author_email": "heylucasleao@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f2/74/48c422d0c4bdbca89c1ef67d567363825d76d6bbaa3ec2c5265ac545d799/tinycp-0.0.5.tar.gz",
    "platform": null,
    "description": "# TinyCP\nTinyCP 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.\n\nFor more information on a previous project related to Out-of-Bag (OOB) solutions, visit [this link](https://github.com/HeyLucasLeao/cp-study).\n\n## Changes about previous work\n- `calibrate`: instead of `Balanced Accuracy Score`, it can be calibrated either `Matthews Correlation Coefficient` or `Bookmaker Informedness Score`, for better reliability\n- `evaluate`: scores `bm` and `mcc` for more reliability\n\nCurrently, TinyCP supports Out-of-Bag (OOB) solutions for `RandomForestClassifier` in binary classification problems. For more options and advanced features, consider exploring [Crepes](https://github.com/henrikbostrom/crepes).\n\n## Installation\n\nInstall TinyCP using pip:\n\n```bash\npip install tinycp\n```\n\n> **Note:** If you want to enable plotting capabilities, you need to install the extras using Poetry:\n\n```bash\npoetry install --E plot\n```\n\n## Usage\n\n### Importing Classes\n\nImport the conformal classifiers from the `tinycp.classifier` module:\n\n```python\nfrom tinycp.classifier.class_conditional import BinaryClassConditionalConformalClassifier\nfrom tinycp.classifier.marginal import BinaryMarginalConformalClassifier\n```\n\n### Example\n\nExample usage of `BinaryClassConditionalConformalClassifier`:\n\n```python\nfrom sklearn.ensemble import RandomForestClassifier\nfrom tinycp.classifier.class_conditional import OOBBinaryClassConditionalConformalClassifier\n\n# Create and fit a RandomForestClassifier\nlearner = RandomForestClassifier(n_estimators=100, oob_score=True)\nX_train, y_train = ...  # your training data\nlearner.fit(X_train, y_train)\n\n# Create and fit the conformal classifier\nconformal_classifier = BinaryClassConditionalConformalClassifier(learner)\nconformal_classifier.fit(y=y_train, oob=True)\n\n# Make predictions\nX_test = ...  # your test data\npredictions = conformal_classifier.predict(X_test)\n```\n\n### Evaluating the Classifier\n\nEvaluate the performance of the conformal classifier using the `evaluate` method:\n\n```python\nresults = conformal_classifier.evaluate(X_test, y_test)\nprint(results)\n```\n\n## Classes\n\n### BinaryMarginalConformalClassifier\n\n`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.\n\n\n### BinaryClassConditionalConformalClassifier\n\n`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.\n\n## License\n\nThis project is licensed under the MIT License.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A small toolbox for conformal prediction",
    "version": "0.0.5",
    "project_urls": null,
    "split_keywords": [
        "machine-learning",
        " conformal-prediction"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "694a4341b3279843198cdfae517add816b457684bde6abe5ff5ed485a22045a1",
                "md5": "0e7328bc6de6594c9d349af3d958e4eb",
                "sha256": "6ce1a8f5d1a4913c1dc303243af687db26d537ed74257c7acba4adc70fc3170a"
            },
            "downloads": -1,
            "filename": "tinycp-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e7328bc6de6594c9d349af3d958e4eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 14813,
            "upload_time": "2025-01-19T03:01:37",
            "upload_time_iso_8601": "2025-01-19T03:01:37.829691Z",
            "url": "https://files.pythonhosted.org/packages/69/4a/4341b3279843198cdfae517add816b457684bde6abe5ff5ed485a22045a1/tinycp-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f27448c422d0c4bdbca89c1ef67d567363825d76d6bbaa3ec2c5265ac545d799",
                "md5": "d8c5f2461a4a774a2fb2d1c394808991",
                "sha256": "7bc8aec5410ca921035af674a3efa4e9c12556297af32b40d16fab0624d2fac5"
            },
            "downloads": -1,
            "filename": "tinycp-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "d8c5f2461a4a774a2fb2d1c394808991",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 11447,
            "upload_time": "2025-01-19T03:01:40",
            "upload_time_iso_8601": "2025-01-19T03:01:40.047918Z",
            "url": "https://files.pythonhosted.org/packages/f2/74/48c422d0c4bdbca89c1ef67d567363825d76d6bbaa3ec2c5265ac545d799/tinycp-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-19 03:01:40",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tinycp"
}
        
Elapsed time: 1.02216s