Traditional software either works or crashes with an explicit stack trace. Machine learning models, however, fail silently: a model deployed to production can continue returning HTTP 200 OK responses with valid-looking numbers, while its actual real-world accuracy degrades catastrophically due to shifts in user behavior, market inflation, or sensor wear.
| Drift Type | Mathematical Definition | Real-World Industrial Example |
|---|---|---|
| Data Drift (Covariate Shift) | P(X) changes while P(y | X) remains constant. The distribution of input features shifts. |
A camera model trained on sunny photos is deployed in a rainy city. Pixel inputs change, but the relationship between cars and objects remains the same. |
| Concept Drift | P(y | X) changes while P(X) may remain unchanged. The statistical relationship between features and target shifts. |
During the 2020 pandemic, consumer purchasing habits changed overnight. A salary of $60,000 in 2018 may no longer predict home approval in 2026 due to inflation. |
The two-sample KS-Test is a non-parametric test comparing the continuous cumulative empirical distributions of a feature in training data vs. live production inference data. If the resulting p-value < 0.05, statistically significant data drift is flagged!
Widely used in risk scoring and fintech, PSI quantifies how much a variable has shifted over time:
PSI = ∑ (Actual% - Expected%) · ln( Actual% / Expected% )
from scipy.stats import ks_2samp
import numpy as np
# Training distribution (baseline) vs Production inference stream (drifted)
baseline_income = np.random.normal(loc=55000, scale=12000, size=1000)
prod_income_drifted = np.random.normal(loc=68000, scale=14000, size=1000)
# Run two-sample KS test
stat, p_value = ks_2samp(baseline_income, prod_income_drifted)
print(f"KS Statistic: {stat:.4f}, P-value: {p_value:.4e}")
if p_value < 0.05:
print("ALERT: Statistically significant Data Drift detected! Firing webhook to trigger CI/CD retraining...")
Broaden your foundational and advanced Machine Learning knowledge across our curriculum:
Trigger scheduled GitHub Actions or Kubernetes jobs when drift occurs.
Detect missing features and distribution shifts in incoming requests.
Step-by-step post-mortem analysis for failing production models.
Statistical tests (KS-test, PSI, Jensen-Shannon) explained.