Skip to main content

A lightweight Python library for monitoring data and concept drift in machine learning models.

Project description

Drift Guard

License: MIT
Version: 0.1.1

DriftGuard is a simple, flexible, and effective library for detecting data drift and concept drift in your machine learning models. It helps you keep track of model performance in production and catch problems early, so you can fix them before they impact your results.

Why DriftGuard?

Models are powerful, but they aren't immune to change. Data drift and concept drift are inevitable as the world changes around you. DriftMonitor helps by automatically monitoring your model's predictions and data features to ensure they're still working as expected.

Concept drift occurs when the underlying relationship between input data and predictions changes over time. Data drift happens when the distribution of your input data shifts, which can degrade model performance.

Detecting this drift before it hurts your model is crucial for maintaining the accuracy of your predictions.

Features

  • Real-Time & Batch Monitoring: Monitor your model's performance in real time or in batch mode.
  • Automatic Drift Detection: Instantly detects feature and concept drift.
  • Performance Tracking: Keeps track of performance metrics, so you know when your model is underperforming.
  • Alert System: Get email alerts whenever drift is detected.
  • Easy to Integrate: No complicated setup – just plug it into your existing machine learning pipeline.

Install

To install DriftGuard, simply run:

pip install driftguard

Usage

Here’s a simple example of how to use DriftGuard with a model.

Example: Monitoring Model Performance

from driftguard import Wrapper
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris

# Load dataset
data = load_iris()
X = pd.DataFrame(data.data, columns=data.feature_names)
y = data.target

# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a model
model = RandomForestClassifier(random_state=42)
model.fit(X_train, y_train)

# Initialize DriftMonitor
monitor = Wrapper(
    model=model,
    reference_data=X_train,
    alert_email="alerts@company.com",
    monitor_name="Iris Model Monitor"
)

# Monitor new data
results = monitor.monitor(X_test, y_test)

print(f"Drift Detected: {results['has_drift']}")
print(f"Performance: {results['performance']}")

It’s that simple. You can now monitor how well your model performs over time and be alerted if something goes wrong.

The Theory Behind Drift Detection

Concept Drift

When the relationship between inputs and outputs changes over time, that’s concept drift. Imagine you have a model that predicts house prices, but after a while, the factors that drive those prices shift. Concept drift happens when the model's understanding of what affects price changes as well.

Data Drift

Data drift is when the distribution of the input data changes. For example, if your model is trained on customer data from the last year, but this year’s data has a slightly different distribution, this is data drift. DriftMonitor catches that shift and lets you know when it happens.

Detection Methods

  • KS Test: A statistical test to compare distributions of features between two datasets.
  • JSD: Measures how similar two probability distributions are.
  • PSI: Used for categorical and continuous features, helps track distribution stability.

DriftMonitor uses these techniques (and more) to detect when your model or data is drifting.

Integration Examples

API-Based Monitoring (FastAPI Example)

from fastapi import FastAPI
import pandas as pd
from driftguard import Wrapper

app = FastAPI()

# Initialize DriftMonitor
drift_monitor = Wrapper(
    model=trained_model,
    reference_data=training_data,
    alert_email="ml-team@company.com"
)

@app.post("/predict")
async def predict(data: dict):
    input_data = pd.DataFrame([data])
    monitor_results = drift_monitor.monitor(input_data)
    prediction = trained_model.predict(input_data)[0]
    
    return {
        "prediction": prediction,
        "drift_detected": monitor_results['has_drift'],
        "drift_scores": monitor_results['drift_scores']
    }

This is just one way you can use DriftGuard. It fits easily into your workflow, whether you're working with batch processing, real-time APIs, or other machine learning pipelines.

Contributing

Want to contribute? Awesome! Here’s how you can help:

  1. Fork the repository.
  2. Make your changes.
  3. Submit a pull request!

License

DriftGuard is licensed under the MIT License. You can find the full text in the LICENSE file.

Cite This Work

If you use DriftGuard in your research, please cite it like this:

@software{korir2025driftmonitor,
  author = {Kiplangat Korir},
  title = {Drift Guard: A Python Library for Monitoring Data and Concept Drift in Machine Learning},
  year = {2025},
  url = {https://github.com/kiplangatkorir/driftguard},
  version = {0.1.0},
  license = {MIT}
}

Or include this text:

Korir, Kiplangat. (2025). Drift Guard: A Python Library for Monitoring Data and Concept Drift in Machine Learning. Version 0.1.0. Available at: https://github.com/kiplangatkorir/driftguard.

Contact

Have any questions? Want to give feedback? Reach out to me at:

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-0.1.2.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

driftguard-0.1.2-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file driftguard-0.1.2.tar.gz.

File metadata

  • Download URL: driftguard-0.1.2.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for driftguard-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7b74df0519d9e610aa803891ea1503e1585390b90158b48d49aba1153e8def1b
MD5 b361dd6306600a4ee2388f1e1ec2bbf8
BLAKE2b-256 811eec3643c3677ac009d95aaed5d90068a549911eea7c1f63ea0679d6c2fa2c

See more details on using hashes here.

File details

Details for the file driftguard-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: driftguard-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for driftguard-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec1fd1f313f16d1cfbcffdd94fe1edaa2f3f04cfc1e3d4d0608dbb62e88399a5
MD5 f5b441e51c4024f84fc90f1f4481fb7a
BLAKE2b-256 8bd1ef16be06e7eccc39f65b9f2bdc09315526dcaf212e038ef02aa5c1ffaa5d

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