0
0
MLOpsdevops~10 mins

Data drift detection basics in MLOps - Commands & Configuration

Choose your learning style9 modes available
Introduction
Data drift detection helps you notice when the data your machine learning model sees changes over time. This is important because changes in data can make your model less accurate or reliable.
When your model is running in production and you want to check if new data is different from training data.
When you want to alert your team if the input data changes unexpectedly.
When you want to decide if your model needs retraining because the data has shifted.
When monitoring data quality to keep your predictions trustworthy.
When comparing data from different time periods to spot trends or issues.
Commands
This command installs the Evidently library, which helps detect data drift easily in Python.
Terminal
pip install evidently
Expected OutputExpected
Collecting evidently Downloading evidently-0.3.39-py3-none-any.whl (123 kB) Installing collected packages: evidently Successfully installed evidently-0.3.39
Runs a Python script that loads reference and current data, then checks for data drift using Evidently.
Terminal
python detect_drift.py
Expected OutputExpected
Data drift detected: True Drift score: 0.35
Key Concept

If you remember nothing else from this pattern, remember: detecting data drift early helps keep your model accurate and trustworthy.

Code Example
MLOps
import pandas as pd
from evidently.dashboard import Dashboard
from evidently.tabs import DataDriftTab

# Load reference data (training data)
reference_data = pd.read_csv('reference_data.csv')

# Load current data (new incoming data)
current_data = pd.read_csv('current_data.csv')

# Create a dashboard to check data drift
dashboard = Dashboard(tabs=[DataDriftTab()])
dashboard.calculate(reference_data, current_data)

# Save the report as an HTML file
dashboard.save('data_drift_report.html')

# Simple drift detection boolean
from evidently.metrics import DataDriftMetric
metric = DataDriftMetric()
result = metric.calculate(reference_data, current_data)
print(f"Data drift detected: {result['metrics']['dataset_drift']}")
print(f"Drift score: {result['metrics']['drift_score']}")
OutputSuccess
Common Mistakes
Not comparing current data to a proper reference dataset.
Without a good baseline, the drift detection will be meaningless or misleading.
Always use a clean, representative dataset from training or a stable period as your reference.
Ignoring data preprocessing differences between reference and current data.
Differences in data format or cleaning can look like drift but are just processing mismatches.
Apply the same preprocessing steps to both datasets before drift detection.
Summary
Install the Evidently library to help detect data drift in Python.
Load your reference (training) and current (new) datasets for comparison.
Use Evidently's dashboard and metrics to identify if data drift has occurred.
Early detection of data drift helps maintain model accuracy and trust.
Always preprocess data consistently and use a good reference dataset.