Skip to main content

A robust data drift detection and schema validation library for machine learning pipelines.

Project description

DriftGuard

DriftGuard is a lightweight, robust, and publish-ready Python library designed to automate dataset validation and detect statistical data drift in machine learning pipelines.

By comparing new incoming datasets against a trusted baseline reference dataset, DriftGuard alerts you to schema changes, increases in missing values, or shifts in feature distributions before they affect downstream model performance.


Features

  • Schema Validation: Detect missing columns, new columns, and data type mismatches.
  • Null Rate Analysis: Monitor and flag columns where the rate of missing values increases beyond a configurable threshold.
  • Statistical Drift Detection:
    • Kolmogorov-Smirnov (KS) Test (scipy.stats.ks_2samp) for numerical columns.
    • Chi-Square Test (scipy.stats.chi2_contingency) for categorical columns.
  • Severity Tagging: Categorizes issues as INFO, WARNING, or CRITICAL for pipeline routing or CI/CD gate checks.
  • Interactive Reports:
    • An ASCII summary table output directly to console.
    • Machine-readable JSON output for automated pipelines.
    • A beautiful, self-contained interactive HTML dashboard with per-column breakdowns and interactive searching/filtering.

Installation

pip install driftguard

Note: Depends on numpy, pandas, and scipy only.


Quickstart

Validate your production features in real-time or as part of a batch training/inference pipeline:

import numpy as np
import pandas as pd
import driftguard as dg

# 1. Create a reference dataset (baseline)
np.random.seed(42)
ref_data = {
    "age": np.random.normal(35, 10, 1000),
    "income": np.random.uniform(30000, 120000, 1000),
    "city": np.random.choice(["New York", "Chicago", "San Francisco"], 1000),
    "target": np.random.choice([0, 1], 1000, p=[0.7, 0.3])
}
reference_df = pd.DataFrame(ref_data)

# 2. Create a new dataset (with some drift and schema issues)
new_data = {
    "age": np.random.normal(38, 10, 1000),                 # Slight shift
    "income": np.random.uniform(30000, 120000, 1000),
    "city": np.random.choice(["New York", "Chicago", "Boston"], 1000),  # "Boston" is a new category
    "target": np.random.choice([0, 1], 1000, p=[0.7, 0.3]),
    "extra_col": np.random.random(1000)                    # New column
}
new_df = pd.DataFrame(new_data)
# Add some null values to 'income'
new_df.loc[np.random.choice(1000, 150, replace=False), "income"] = np.nan

# 3. Instantiate Validator and run checks
# p_threshold matches the significance alpha for KS/Chi2
# null_threshold is the maximum allowed null rate increase
validator = dg.Validator(reference_df, p_threshold=0.05, null_threshold=0.10)
report = validator.check(new_df)

# 4. Consume the report
# Prints a formatted ASCII table of all issues
report.summary()

# Export interactive HTML dashboard (saves report.html)
report.export("html")

# Export machine-readable JSON (saves report.json)
report.export("json")

License

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

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

driftguard_prathvi-0.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

driftguard_prathvi-0.1.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file driftguard_prathvi-0.1.0.tar.gz.

File metadata

  • Download URL: driftguard_prathvi-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for driftguard_prathvi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0bc282fbf7ad790d8a564d5d6aa799735a58a637ab235157796cacd06ef938c9
MD5 bad63325d32317f4e10033bde86c29c4
BLAKE2b-256 71050be5ded92385e2501853ebe03d5f23b68be0f02f87759267099a00d4e440

See more details on using hashes here.

File details

Details for the file driftguard_prathvi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for driftguard_prathvi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fecc05a74595e9789fddabcf42e9d1d172824e61da1401b0f2dde222b4e7150
MD5 ede9bb841c0eb06d113e5e021635a6a2
BLAKE2b-256 a74e9c34759ec8cd9541f0f02fa7bd2d4161926f944b45e082573d5a93b12391

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