Skip to main content

The official safetycage package for misclassification detection in predictive models.

Project description

SafetyCage

SafetyCage is a Python package for detecting misclassified predictions from machine learning models in classification tasks. It provides a unified interface for multiple statistical detection methods, enabling users to quantify prediction reliability and flag potentially incorrect outputs across different models and datasets easily.

It is available on PyPI here: https://pypi.org/project/safetycage/.

Background

The idea behind safetycage is that we can find statistics on each predicted sample and compare that statistic to some statistic threshold “alpha” to predict whether the sample prediction was incorrectly classified.

Description

Machine learning models can produce incorrect predictions with high confidence. SafetyCage addresses this by providing post-hoc misclassification detection methods that operate on model outputs or internal representations.

The package includes several methods:

  • MSP (Maximum Softmax Probability)
  • DOCTOR (Error probability estimation)
  • Mahalanobis (Distance-based statistical testing)
  • SPARDACUS (Projection + density estimation approach)

Each method outputs a statistic or p-value that reflects how likely a prediction is to be incorrect.

Alternatively, you can implement your own method by initializing a base class from the safetycage abstract base class, which defines how methods should be implemented.

Requirements

Currently, safetyCage requires Python 3.11.7. Consider creating an environment for your project with safetycage that uses Python 3.11.7.

We are working to make this more flexible.

Installation

Install via pip using the command:

pip install safetycage

The dependencies should be automatically installed when you install safetycage. If not, consider seeing the dependencies listed in the pyproject.toml available on GitHub.

Tutorials & Examples

To learn how to use safetycage, check out the safetycage tutorials available at https://github.com/safety-cage/safetycage-tutorials. These provide full examples and tutorials on how to use safetycage, and thus also providing scripts to train models to test the safetycage methods on!

Changelog

See the CHANGELOG.MD for details on versioning.

Support

If you encounter issues or have questions:

Contributing

If you would like to contribute, please reach out to our safetycage team, listed below!

Authors

Acknowledgment

The MSP method was introduced by Hendrycks and Gimpel in A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks.

The DOCTOR method was introduced by Granese et al. in DOCTOR: A Simple Method for Detecting Misclassification Errors.

A proper citation for these methods is provided in the docstring of the code using these methods.

A special thank you goes to previous co-authors of the methods we have built, Filippo Remonato, Shawn Benedict, and Albert Ndur-Osei.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project status

Active and under development!

Citation

If you use safetycage, please cite us!

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

safetycage-0.0.5.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safetycage-0.0.5-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file safetycage-0.0.5.tar.gz.

File metadata

  • Download URL: safetycage-0.0.5.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for safetycage-0.0.5.tar.gz
Algorithm Hash digest
SHA256 11486fa7da676cf501a0259a6e1117fd9ed8b9897e6592956d4d039b1080e372
MD5 3c28529400d99a17c581c224e48e8f7f
BLAKE2b-256 b3e7786fc435b0f414592d3a841b5e86e540a662a438915e329623323c5603c7

See more details on using hashes here.

File details

Details for the file safetycage-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: safetycage-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for safetycage-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 54ff8bf8c89c3b6b661c46ca934603bb44ea22a85fc5239f1094365e8207b297
MD5 facd3651ba1ab2b4d4038b7173a9847b
BLAKE2b-256 9cd47fcc79b58da44ee4467ac0882b73cf0e80fed1e23da7e35e983ea48da0fe

See more details on using hashes here.

Supported by

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