Skip to main content

Machine learning with a reject option

Project description

PyPi Python package workflow License PythonVersion Black linting: 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.

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.

🏗 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.

pip install -U scikit-fallback

📚 Examples

See the 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scikit_fallback-0.1.1.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

scikit_fallback-0.1.1-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file scikit_fallback-0.1.1.tar.gz.

File metadata

  • Download URL: scikit_fallback-0.1.1.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for scikit_fallback-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6e4635c93bfade2ffff18cf36a300d5cc45e921d5221a57aa4a16213a41932e5
MD5 e4c67893bce89cb51a99e6ee4104a569
BLAKE2b-256 1dde63fe8d5f82b5b1066b96c4439d63f9eed36914218e68152cf5d32cad6055

See more details on using hashes here.

File details

Details for the file scikit_fallback-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for scikit_fallback-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f351387f71173b90edf10ab4a75fa193239a6bcb627b2073bee8e66ad6297545
MD5 a8094169edfa1f787d50a2686e0aec37
BLAKE2b-256 d9e3191bdb820e5e89744573ca82e37bf5c5f85ecd67de10b0ea18ade2866fd2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page