Production ML Monitoring: Data Drift & Concept Drift

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.

Data Drift vs. Concept Drift

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.

Statistical Methods to Detect Drift

1. Kolmogorov-Smirnov (KS) Test

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!

2. Population Stability Index (PSI)

Widely used in risk scoring and fintech, PSI quantifies how much a variable has shifted over time:

PSI = ∑ (Actual% - Expected%) · ln( Actual% / Expected% )

  • PSI < 0.10: No significant shift; model is stable.
  • 0.10 ≤ PSI < 0.25: Moderate drift detected; schedule model review.
  • PSI ≥ 0.25: Severe distribution drift! Trigger automated retraining immediately.
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...")

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. What is Ground Truth Delay?

In many industries (e.g. loan defaults or disease outcomes), you may not learn whether a prediction was correct until months or years later. Monitoring input Data Drift (P(X)) serves as an early warning system before ground truth is known.

Q2. What is Evidently AI?

Evidently AI is a popular open-source Python library that generates interactive HTML dashboards and JSON health reports monitoring data drift, target drift, and model quality metrics in production.

Q3. What is Continuous Training (CT)?

CT is the practice where drift detection alerts automatically trigger an orchestration pipeline (Airflow, Kubeflow) to ingest fresh data, retrain the model, validate metrics against a holdout test set, and deploy the updated weights without manual engineering intervention.

Explore Related Machine Learning Tutorials & Next Steps

Broaden your foundational and advanced Machine Learning knowledge across our curriculum:

Automated Retraining Pipelines

Trigger scheduled GitHub Actions or Kubernetes jobs when drift occurs.

Feature Engineering Safeguards

Detect missing features and distribution shifts in incoming requests.

Debugging Production Degradation

Step-by-step post-mortem analysis for failing production models.

Interview Q&A: Data vs Concept Drift

Statistical tests (KS-test, PSI, Jensen-Shannon) explained.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!