Metadata-Version: 2.1
Name: scikit-fallback
Version: 0.1.0
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
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python
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: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scikit-learn>=1.0
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.

### 👩‍💻 Usage

To allow your probabilistic pipeline to *fallback*—i.e., abstain from predictions—you can
wrap it with a `skfb` *rejector*. Training a rejector means both fitting your model and
learning to accept or reject predictions. Evaluation of a rejector depends
on *fallback mode* (inference with or without *fallback labels*) and measures the ability
of the rejector to both accept correct predictions and reject ambiguous ones.

For example, `skfb.estimators.ThresholdFallbackClassifierCV` fits the base estimator and then
finds the best confidence threshold via cross-validation. If `fallback_mode == "store"`, then the
rejector returns `skfb.core.array.FBNDArray` of predictions and a sparse fallback-mask property,
which lets us summarize the accuracy of both predictions and rejections.

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

rejector = ThresholdFallbackClassifierCV(
    LogisticRegressionCV(cv=4, random_state=0),
    thresholds=10,
    ambiguity_threshold=0.05,
    cv=5,
    fallback_label=-1,
    fallback_mode="store",
)
rejector.fit(X_train, y_train)  # Train base estimator and learn best threshold
rejector.score(X_test, y_test)  # Compute acceptance-correctness accuracy score
```

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


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

If you already have `scikit-learn` installed and it's `scikit-learn<=1.2`, make sure that `numpy<2.0`
to prevent incompatibility issues.

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


### 📚 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
