Metadata-Version: 2.1
Name: scikit-fallback
Version: 0.0.1
Summary: Machine learning with a reject option
Author: Sanjar Ad[yi]lov
Maintainer: Sanjar Ad[yi]lov
License: BSD 3-Clause License
        
        Copyright (c) 2024, Sanjar Ad[yi]lov.
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
        
        * Neither the name of the copyright holder nor the names of its
          contributors may be used to endorse or promote products derived from
          this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/sanjaradylov/scikit-fallback
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scikit-learn>=1.3
Provides-Extra: tests
Requires-Dist: black>=24.4.0; extra == "tests"
Requires-Dist: matplotlib>=3.0; extra == "tests"
Requires-Dist: pre-commit>=3.7.0; extra == "tests"
Requires-Dist: pylint>=3.1.0; extra == "tests"
Requires-Dist: pytest>=8.0; extra == "tests"
Provides-Extra: dev
Requires-Dist: jupyterlab; extra == "dev"
Provides-Extra: examples
Requires-Dist: matplotlib>=3.0; extra == "examples"

![PyPi](https://img.shields.io/pypi/v/scikit-fallback)
![Python package workflow](https://github.com/sanjaradylov/scikit-fallback/actions/workflows/python-package.yml/badge.svg)
![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)
[![PythonVersion](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/downloads/release/python-3913/)
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint)

**scikit-fallback** is a scikit-learn-compatible Python package for machine learning
with a reject option.


### 🏗 Installation
`scikit-fallback` requires:
* Python (>=3.9,< 3.13)
* scikit-learn (>=1.3)
* matplotlib (>=3.0) (optional)

```bash
pip install -U scikit-fallback
```

### 👩‍💻 Usage

To allow your model to *fallback*—i.e., abstain from predictions—you can wrap your
classification pipeline with a `scikit-fallback` *rejector* and then train the final
pipeline and evaluate both the classifier's and the rejector's performance.

For example, `RateFallbackClassifierCV` fits the base estimator and then finds the best
confidence threshold s.t. the fallback rate on the held-out set is <= the provided value.
If `fallback_mode == "store"`, then the rejector returns *FBNDArrays* of predictions
and a sparse fallback-mask property, which lets us summarize the accuracy of both
predictions and rejections.

```python
from skfb.estimators import RateFallbackClassifierCV
from sklearn.linear_model import LogisticRegressionCV

rejector = RateFallbackClassifierCV(
    LogisticRegressionCV(cv=4, random_state=0),
    fallback_rates=(0.05, 0.06, 0.07),
    cv=5,
    fallback_label=-1,
    fallback_mode="store",
)
rejector.fit(X_train, y_train)
rejector.score(X_test, y_test)
```

For more information, see the project's [Wiki](https://github.com/sanjaradylov/scikit-fallback/wiki).


### 📚 Examples

See the [`examples/`](examples/) directory for various applications of fallback estimators
and scorers to scikit-learn-compatible pipelines.

### 🔗 References

1. Hendrickx, K., Perini, L., Van der Plas, D. et al. Machine learning with a reject option: a survey. Mach Learn 113, 3073–3110 (2024). https://doi.org/10.1007/s10994-024-06534-x
