0
0
MLOpsdevops~10 mins

Data drift detection in MLOps - Commands & Configuration

Choose your learning style9 modes available
Introduction
Data drift detection helps you find when the data your machine learning model sees changes over time. This is important because changes in data can make your model less accurate and reliable.
When your model is deployed 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 due to data changes.
When monitoring data quality in production pipelines.
When comparing data distributions between different time periods.
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.43-py3-none-any.whl (123 kB) Installing collected packages: evidently Successfully installed evidently-0.3.43
This runs a Python script that compares new data with reference data to detect drift and prints a report.
Terminal
python detect_drift.py
Expected OutputExpected
Data drift detected: True Drift score: 0.35 Report saved to drift_report.html
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
from evidently.dashboard import Dashboard
from evidently.tabs import DataDriftTab
import pandas as pd

# Load reference and new data
reference_data = pd.read_csv('reference_data.csv')
new_data = pd.read_csv('new_data.csv')

# Create a dashboard for data drift
dashboard = Dashboard(tabs=[DataDriftTab()])
dashboard.calculate(reference_data, new_data)

# Save the report to an HTML file
dashboard.save('drift_report.html')

# Simple drift check example
from evidently.metrics import DataDriftMetric
metric = DataDriftMetric()
result = metric.calculate(reference_data, new_data)
print(f"Data drift detected: {result['metrics']['dataset_drift']}")
print(f"Drift score: {result['metrics']['drift_score']}")
OutputSuccess
Common Mistakes
Not comparing new data to a proper reference dataset.
Without a good baseline, drift detection results are meaningless or misleading.
Always use a clean, representative dataset from training or a stable period as reference.
Ignoring drift alerts and not acting on them.
Ignoring drift can cause your model to make wrong predictions over time.
Set up alerts and retraining pipelines to respond to detected drift.
Summary
Install the Evidently library to enable data drift detection in Python.
Prepare a reference dataset and new data to compare.
Run a script that calculates and reports data drift.
Use the report to monitor data changes and decide when to retrain models.