Skip to main content

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.

Metadata

Release files for redflag 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redflag 0.5.0
File Size Uploaded
redflag-0.5.0.tar.gz 1.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for redflag 0.5.0
File Interpreter ABI Platform
redflag-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.3 MB

Release files / redflag-0.5.0.tar.gz

Download URL redflag-0.5.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
11c452c0b44b9e1606cddda4ae4de9fae270a0531732d58d1fbc6d9d255e6f3c
BLAKE2b-256 checksum
How to use checksums
e1e4909842249edc505b017070a6ecd159e073af80bb20a3bf23e6eac37c8ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / redflag-0.5.0-py3-none-any.whl

Download URL redflag-0.5.0-py3-none-any.whl
Size 53.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7081ebdb63af9b44e336f9c3cd40caf3311b5fa478eaf70ad5de934f05f1362f
BLAKE2b-256 checksum
How to use checksums
ffb90d366935f02f82629a64ac836e62fab1150890f6ae5113ed6250e0d67cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page