conformist


Nameconformist JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
SummaryConformal prediction for machine learning classifiers
upload_time2024-11-02 09:23:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Mariya Lysenkova Wiklander Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords machinelearning statistics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- Link to Google Font -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=League+Script&display=swap" rel="stylesheet">
<link href="readme.css" rel="stylesheet">


[![Python package](https://github.com/Molmed/conformist/actions/workflows/python-package.yml/badge.svg)](https://github.com/Molmed/conformist/actions/workflows/python-package.yml)
[![Upload Python Package](https://github.com/Molmed/conformist/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Molmed/conformist/actions/workflows/python-publish.yml)


<h1 class="custom-font miami-neon-text">Conformist</h1>

Conformist v1.0.3 is an implementation of conformal prediction, specifically conformal risk control. It was written using Python 3.8.

*BaseCoP* contains utility functions common to all conformal predictors, such as splitting data into calibration and validation sets, and setting up runs. It is extended by *FNRCoP* that implements conformal risk control.

The *ValidationRun* class contains the data from a single run, which entails shuffling the data randomly, splitting it into calibration and validation datasets, calibrating the conformal predictor on the calibration data and creating prediction sets for the validation data.

The *ValidationTrial* class contains a list of runs and calculates statistics across these runs.

## Installation
`pip install conformist`

## Input file format

The input to Conformist is a CSV file with the following columns:
`id, known_class, predicted_class, [proba_columns]`

The proba_columns should contain class-specific probability scores and correspond to the names used in the `known_class` and `predicted_class` columns.

Example:
| id      | known_class | predicted_class | ClassA | ClassB | ClassC |
| --------| ----------- | --------------- | ------ | ------ | ------ |
| Sample1 | ClassB      | ClassA          | 0.70   | 0.25   | 0.05   |
| Sample2 | ClassA      | ClassA          | 0.98   | 0.02   | 0.0    |
| Sample3 | ClassC      | ClassC          | 0.01   | 0.01   | 0.98   |

## Example implementation
```
from conformist import FNRCoP, PredictionDataset, ValidationTrial

CALIB_DATA_CSV = 'path/to/calib.csv'
TEST_DATA_CSV = 'path/to/test.csv'
OUTPUT_DIR = 'path/to/output'
ALPHA = 0.05 # Select a reasonable False Negative Rate

# Read in formatted predictions
calpd = PredictionDataset(predictions_csv=CALIB_DATA_CSV,
                          dataset_name='my_cal_data')
testpd = PredictionDataset(predictions_csv=TEST_DATA_CSV,
                           dataset_name='my_test_data')

# Get class counts and prediction heatmap
calpd.run_reports(OUTPUT_DIR)

# Validation trial and reports
mcp = FNRCoP(calpd, alpha=ALPHA)
trial = mcp.do_validation_trial(n_runs=10000)
trial.run_reports(OUTPUT_DIR)

# Recalibrate conformal predictor
mcp = FNRCoP(calpd, alpha=ALPHA)
mcp.calibrate()

# Predict
formatted_predictions = mcp.predict(testpd,
                                    OUTPUT_DIR)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "conformist",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "machinelearning, statistics",
    "author": null,
    "author_email": "Mariya Lysenkova Wiklander <mariya.lysenkova@medsci.uu.se>",
    "download_url": "https://files.pythonhosted.org/packages/13/08/56880b172aaec990ccf3e7c1812dac57b56ee7973e96d9793f844270abe9/conformist-1.0.3.tar.gz",
    "platform": null,
    "description": "<!-- Link to Google Font -->\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n<link href=\"https://fonts.googleapis.com/css2?family=League+Script&display=swap\" rel=\"stylesheet\">\n<link href=\"readme.css\" rel=\"stylesheet\">\n\n\n[![Python package](https://github.com/Molmed/conformist/actions/workflows/python-package.yml/badge.svg)](https://github.com/Molmed/conformist/actions/workflows/python-package.yml)\n[![Upload Python Package](https://github.com/Molmed/conformist/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Molmed/conformist/actions/workflows/python-publish.yml)\n\n\n<h1 class=\"custom-font miami-neon-text\">Conformist</h1>\n\nConformist v1.0.3 is an implementation of conformal prediction, specifically conformal risk control. It was written using Python 3.8.\n\n*BaseCoP* contains utility functions common to all conformal predictors, such as splitting data into calibration and validation sets, and setting up runs. It is extended by *FNRCoP* that implements conformal risk control.\n\nThe *ValidationRun* class contains the data from a single run, which entails shuffling the data randomly, splitting it into calibration and validation datasets, calibrating the conformal predictor on the calibration data and creating prediction sets for the validation data.\n\nThe *ValidationTrial* class contains a list of runs and calculates statistics across these runs.\n\n## Installation\n`pip install conformist`\n\n## Input file format\n\nThe input to Conformist is a CSV file with the following columns:\n`id, known_class, predicted_class, [proba_columns]`\n\nThe proba_columns should contain class-specific probability scores and correspond to the names used in the `known_class` and `predicted_class` columns.\n\nExample:\n| id      | known_class | predicted_class | ClassA | ClassB | ClassC |\n| --------| ----------- | --------------- | ------ | ------ | ------ |\n| Sample1 | ClassB      | ClassA          | 0.70   | 0.25   | 0.05   |\n| Sample2 | ClassA      | ClassA          | 0.98   | 0.02   | 0.0    |\n| Sample3 | ClassC      | ClassC          | 0.01   | 0.01   | 0.98   |\n\n## Example implementation\n```\nfrom conformist import FNRCoP, PredictionDataset, ValidationTrial\n\nCALIB_DATA_CSV = 'path/to/calib.csv'\nTEST_DATA_CSV = 'path/to/test.csv'\nOUTPUT_DIR = 'path/to/output'\nALPHA = 0.05 # Select a reasonable False Negative Rate\n\n# Read in formatted predictions\ncalpd = PredictionDataset(predictions_csv=CALIB_DATA_CSV,\n                          dataset_name='my_cal_data')\ntestpd = PredictionDataset(predictions_csv=TEST_DATA_CSV,\n                           dataset_name='my_test_data')\n\n# Get class counts and prediction heatmap\ncalpd.run_reports(OUTPUT_DIR)\n\n# Validation trial and reports\nmcp = FNRCoP(calpd, alpha=ALPHA)\ntrial = mcp.do_validation_trial(n_runs=10000)\ntrial.run_reports(OUTPUT_DIR)\n\n# Recalibrate conformal predictor\nmcp = FNRCoP(calpd, alpha=ALPHA)\nmcp.calibrate()\n\n# Predict\nformatted_predictions = mcp.predict(testpd,\n                                    OUTPUT_DIR)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Mariya Lysenkova Wiklander  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Conformal prediction for machine learning classifiers",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/Molmed/conformist"
    },
    "split_keywords": [
        "machinelearning",
        " statistics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd7ea7c2ccf99edc639853f4e9afffbb8f90c21fc324612168504ca4817ea06b",
                "md5": "76c7c5481e21cb29a6337e0a53c35a5f",
                "sha256": "fbb8e789c293f976125aff1842f04e4c4ef5a4b6ce9027eaa9e6e15a6075d2a2"
            },
            "downloads": -1,
            "filename": "conformist-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "76c7c5481e21cb29a6337e0a53c35a5f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18128,
            "upload_time": "2024-11-02T09:23:21",
            "upload_time_iso_8601": "2024-11-02T09:23:21.451611Z",
            "url": "https://files.pythonhosted.org/packages/fd/7e/a7c2ccf99edc639853f4e9afffbb8f90c21fc324612168504ca4817ea06b/conformist-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "130856880b172aaec990ccf3e7c1812dac57b56ee7973e96d9793f844270abe9",
                "md5": "c3a6a88bc560881406f481fced386e4d",
                "sha256": "03dfe6d0fa390342ef677297ba6067713202ef08d647a82ad544beb166af43a2"
            },
            "downloads": -1,
            "filename": "conformist-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c3a6a88bc560881406f481fced386e4d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16493,
            "upload_time": "2024-11-02T09:23:23",
            "upload_time_iso_8601": "2024-11-02T09:23:23.318931Z",
            "url": "https://files.pythonhosted.org/packages/13/08/56880b172aaec990ccf3e7c1812dac57b56ee7973e96d9793f844270abe9/conformist-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-02 09:23:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Molmed",
    "github_project": "conformist",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "conformist"
}
        
Elapsed time: 1.26282s