π Data Drift Detection
What you'll learn
How to catch "silent failures" where models degrade because the world changed. A model is only as good as the data it sees β drift detection ensures you know when reality shifts.
FlowyML ensures your models don't rot in production by detecting when live data diverges from training data, using the Population Stability Index (PSI).
Why Drift Detection Matters
| Without Drift Detection | With Drift Detection |
|---|---|
| Model accuracy silently degrades | Proactive alerts on data shifts |
| Users complain about bad predictions weeks later | Know immediately when distributions change |
| Retraining on a fixed schedule (wasteful) | Retrain only when necessary |
| "Why did predictions get worse?" | Root cause: "Feature X shifted by PSI=0.34" |
How PSI Works
The Population Stability Index measures how much a feature's distribution has changed:
| PSI Value | Interpretation | Action |
|---|---|---|
| < 0.1 | No significant drift | β Safe |
| 0.1 β 0.2 | Moderate drift | β οΈ Monitor closely |
| > 0.2 | Significant drift | π¨ Investigate / Retrain |
graph LR
A["Reference Data<br/>(Training Set)"] --> C["compute PSI"]
B["Current Data<br/>(Production)"] --> C
C --> D{"PSI < threshold?"}
D -- Yes --> E["β
Data is stable"]
D -- No --> F["π¨ Drift detected!"]
π΅οΈ Detecting Drift
Use the detect_drift function to compare two datasets:
detect_drift() Return Value
| Key | Type | Description |
|---|---|---|
drift_detected |
bool |
Whether PSI exceeded the threshold |
psi |
float |
Population Stability Index value |
reference_stats |
dict |
Stats of reference data (mean, std, min, max) |
current_stats |
dict |
Stats of current data (mean, std, min, max) |
threshold |
float |
Threshold used for detection |
π Computing Statistics
Compute descriptive statistics for any dataset:
Real-World Examples
Automated Quality Gate
Stop a pipeline if drift is detected β prevent bad predictions from being served:
Multi-Feature Drift Monitoring
Best Practices
Monitor all input features
Don't just check one feature β a model can break if any input feature drifts. Automate checks across all columns.
Set sensible thresholds
PSI < 0.1 is usually safe. PSI > 0.2 requires investigation. Tune based on your domain's tolerance for distribution shift.
Drift β Performance Drop
Drift indicates the data changed, but the model might still perform well. Always pair drift detection with actual performance monitoring.