Skip to main content

Safety net for machine learning pipelines.

Project description

redflag

Tests Docs PyPI version Conda Version PyPI versions PyPI license

🚩 redflag aims to be an automatic safety net for machine learning datasets. The vision is to accept input of a Pandas DataFrame or NumPy ndarray representing the input X and target y in a machine learning task. redflag will provide an analysis of each feature, and of the target, including aspects such as class imbalance, leakage, outliers, anomalous data patterns, threats to the IID assumption, and so on. The goal is to complement other projects like pandas-profiling and greatexpectations.

Installation

You can install this package with pip:

python -m pip install redflag

Alternatively, you can use the conda package manager, pointed at the conda-forge channel:

conda install -c conda-forge redflag

For developers, there is a pip option for installing dev dependencies. Use pip install "redflag[dev]" to install all testing and documentation packages.

Example with sklearn

The most useful components of redflag are probably the scikit-learn "detectors". These sit in your pipeline, look at your training and validation data, and emit warnings if something looks like it might cause a problem. For example, we can get alerted to an imbalanced target vector y like so:

import redflag as rf
from sklearn.datasets import make_classification

X, y = make_classification(weights=[0.1])

_ = rf.ImbalanceDetector().fit(X, y)

This raises a warning:

🚩 The labels are imbalanced by more than the threshold (0.780 > 0.400). See self.minority_classes_ for the minority classes.

For maximum effect, put this and other detectors in your pipeline, or use the pre-build rf.pipeline which contains several useful alerts.

See the documentation, and specifically the notebook Using redflag with sklearn.ipynb for other examples.

Example of function call

redflag is also a collection of functions. Most of the useful ones take one or more columns of data (usually a 1D or 2D NumPy array) and run a single test. For example, we can do some outlier detection. The get_outliers() function returns the indices of data points that are considered outliers:

>>> import redflag as rf
>>> data = 3 * [-3, -2, -2, -1, 0, 0, 0, 1, 2, 2, 3]
>>> rf.get_outliers(data)
array([], dtype=int64)

That is, there are no outliers. But let's add a clear outlier: a new data record with a value of 100. The function returns the index position(s) of the outlier point(s):

>>> rf.get_outliers(data + [100])
array([33])

See the documentation, and specifically the notebook Basic_usage.ipynb for several other basic examples.

Documentation

The documentation is online.

Contributing

Please see CONTRIBUTING.md. There is also a section in the documentation about Development.

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

redflag-0.5.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

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

redflag-0.5.0-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file redflag-0.5.0.tar.gz.

File metadata

  • Download URL: redflag-0.5.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for redflag-0.5.0.tar.gz
Algorithm Hash digest
SHA256 11c452c0b44b9e1606cddda4ae4de9fae270a0531732d58d1fbc6d9d255e6f3c
MD5 5b6b005f6bfa8f9e7c2ed12f56dca0b9
BLAKE2b-256 e1e4909842249edc505b017070a6ecd159e073af80bb20a3bf23e6eac37c8ada

See more details on using hashes here.

File details

Details for the file redflag-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: redflag-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for redflag-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7081ebdb63af9b44e336f9c3cd40caf3311b5fa478eaf70ad5de934f05f1362f
MD5 df3009d9a7c82c0bd0488eec5b8a1e5b
BLAKE2b-256 ffb90d366935f02f82629a64ac836e62fab1150890f6ae5113ed6250e0d67cd8

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