No project description provided
Project description
drift-lite
A comprehensive, lightweight wrapper for scikit-learn models that detects data drift and target drift in production using advanced statistical tests.
Why use drift-lite?
Deployed machine learning models degrade over time as the real-world data distribution shifts away from the training distribution. drift-lite automatically monitors incoming inference requests and alerts you via customizable callbacks if the data distribution shifts significantly.
Features:
- Multiple Statistical Metrics (Kolmogorov-Smirnov, Wasserstein Distance, Chi-Square, Population Stability Index)
- Target Drift Detection (Monitors changes in model predictions)
- First-class Pandas DataFrame Support
- Extensible Callback System (e.g., Webhooks, Logging)
Installation
pip install drift-lite pandas
Quick Start
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from drift_lite import DriftWrapper, DriftConfig, FeatureConfig, LoggingCallback
# 1. Prepare your training data
df_train = pd.DataFrame(np.random.normal(0, 1, (1000, 2)), columns=["feature_A", "feature_B"])
y_train = np.random.randint(0, 2, 1000)
# 2. Configure the drift monitor
config = DriftConfig(
window_size=100,
detect_target_drift=True,
features={
"feature_A": FeatureConfig(type="continuous", metric="ks", threshold=0.05),
"feature_B": FeatureConfig(type="continuous", metric="wasserstein", threshold=0.5)
}
)
# 3. Wrap your model
base_model = RandomForestClassifier()
model = DriftWrapper(
base_model,
config=config,
callbacks=[LoggingCallback()]
)
# 4. Fit the model (it automatically saves a baseline of df_train)
model.fit(df_train, y_train)
# 5. Predict in production
# Normal data (No warning)
df_normal = pd.DataFrame(np.random.normal(0, 1, (100, 2)), columns=["feature_A", "feature_B"])
model.predict(df_normal)
# Drifted data (Emits logging warnings and webhooks)
df_drifted = pd.DataFrame(np.random.normal(2, 1.5, (100, 2)), columns=["feature_A", "feature_B"])
model.predict(df_drifted)
# WARNING: Data drift detected on 'feature_A' using ks (score=0.0001, threshold=0.0500)
# WARNING: Data drift detected on 'model_target' using ks (score=0.0123, threshold=0.0500)
Creating Custom Callbacks
from drift_lite.callbacks import BaseCallback
class SlackAlertCallback(BaseCallback):
def on_drift_detected(self, feature_name, score, metric_name, threshold):
# Ping slack webhook here
print(f"Alerting slack: {feature_name} has drifted!")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drift_lite-0.1.0.tar.gz.
File metadata
- Download URL: drift_lite-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.3 Linux/7.0.11-76070011-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68728205cd7e3127e5e2e9a9098e0da512ae759690d211bd28e0ead40ae2c3c8
|
|
| MD5 |
ead2f7b3c925476d6a0425b1dee6f90f
|
|
| BLAKE2b-256 |
4d276946ec3777fe6053dd2d15b254a2ed5bba9196ad38b1b164c0f7a4aa62f9
|
File details
Details for the file drift_lite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drift_lite-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.3 Linux/7.0.11-76070011-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d6b8ee3d7921dc0c057ad62465dfccdeb3bae446c41aeac335a43758b140d24
|
|
| MD5 |
8491e2063496758561c5ee9ee192003a
|
|
| BLAKE2b-256 |
731da2389b448ce75293c49267fac95ff269370b5a1c104f7121baa71cde7ed7
|