Metadata-Version: 2.1
Name: reject
Version: 0.3.0
Summary: Functionalities for classification with rejection.
Home-page: https://github.com/arthur-thuy/reject
License: Apache-2.0
Author: Arthur Thuy
Maintainer: Arthur Thuy
Maintainer-email: arthur.thuy@telenet.be
Requires-Python: >=3.9,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Dist: matplotlib (>=3.8.3,<4.0.0)
Requires-Dist: numpy (>=1.26.4,<2.0.0)
Requires-Dist: scipy (>=1.12.0,<2.0.0)
Project-URL: Documentation, https://reject.readthedocs.io
Project-URL: Repository, https://github.com/arthur-thuy/reject
Description-Content-Type: text/markdown

# reject

<p align="center">
<a href="https://pypi.org/project/reject/">
        <img alt="PyPI" src="https://img.shields.io/pypi/v/reject">
    </a>
<img src="https://github.com/arthur-thuy/reject/actions/workflows/ci.yml/badge.svg" />
<a href='https://reject.readthedocs.io/en/latest/'>
        <img src='https://img.shields.io/readthedocs/reject' alt='Documentation Status' />
    </a>
<a href="https://app.codecov.io/gh/arthur-thuy/reject" > 
 <img src="https://codecov.io/gh/arthur-thuy/reject/graph/badge.svg?token=wYnaStSR3z"/> 
 </a>
<a href="https://github.com/psf/black">
        <img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
    </a>
</p>

`reject` is a Python library for _classification with rejection_. Neural networks are often confidently wrong when confronted with out-of-distribution data. When the prediction's uncertainty is too high, the model abstains from predicting and the observation is passed on to a human expert who takes the final decision. It is useful for applications where making an error can be more costly than asking a human expert for help.

## Installation

```bash
$ pip install reject
```

## Documentation

The documentation is deployed to [reject.readthedocs.io](http://reject.readthedocs.io/).

## Usage

```python
from reject.reject import ClassificationRejector

y_pred  # Array of predictions. Shape (n_observations, n_classes) or (n_observations, n_samples, n_classes).
y_true  # Array of true labels. Shape (n_observations,).

# initialize the rejector
rej = ClassificationRejector(y_true_all, y_pred_all)
```
```python
# single rejection point
rej.reject(threshold=0.5, unc_type="TU", relative=True, show=True)
```
```bash
             Non-rejected    Rejected
---------  --------------  ----------
Correct               891          20
Incorrect             109         980

  Non-rejected accuracy    Classification quality    Rejection quality
-----------------------  ------------------------  -------------------
                 0.8910                    0.9355              40.9908
```

```python
# rejection curve
fig = rej.plot_reject(unc_type="TU", metric="NRA")
print(fig)
```

<img src="https://github.com/arthur-thuy/reject/assets/57416568/6a59f37a-0f2f-4a2c-96d8-8690b8e19df7" height="200"/>

An example notebook is provided, which can be found in the ["Example usage" section](https://reject.readthedocs.io/en/latest/example.html) of the documentation.

