Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Data Drift Detection
📖 Scenario: You work as a data engineer in a company that uses machine learning models to predict customer behavior. Over time, the data your model sees can change, which might make the model less accurate. This change is called data drift. Detecting data drift early helps keep the model reliable.
🎯 Goal: Build a simple Python program that detects data drift by comparing the distribution of a feature in new data against the original training data.
📋 What You'll Learn
Create a dictionary called training_data with feature values
Create a dictionary called new_data with feature values
Calculate the mean of the feature in both datasets
Set a threshold called drift_threshold to detect drift
Compare the means and print if data drift is detected or not
💡 Why This Matters
🌍 Real World
Data drift detection helps keep machine learning models accurate by alerting when input data changes significantly.
💼 Career
Data engineers and MLOps specialists use data drift detection to maintain and monitor deployed ML models in production.
Progress0 / 4 steps
1
Create training data dictionary
Create a dictionary called training_data with the key 'feature1' and the list of values [10, 12, 11, 13, 12].
MLOps
Hint
Use curly braces to create a dictionary and square brackets for the list of numbers.
2
Create new data dictionary
Create a dictionary called new_data with the key 'feature1' and the list of values [14, 15, 13, 16, 15].
MLOps
Hint
Follow the same format as the training_data dictionary.
3
Calculate means and set threshold
Calculate the mean of feature1 in training_data and store it in mean_training. Calculate the mean of feature1 in new_data and store it in mean_new. Then, create a variable called drift_threshold and set it to 2.0.
MLOps
Hint
Use sum() and len() functions to calculate the mean.
4
Detect and print data drift
Write an if statement to check if the absolute difference between mean_new and mean_training is greater than drift_threshold. If yes, print "Data drift detected". Otherwise, print "No data drift detected".
MLOps
Hint
Use abs() to get the absolute difference.
Practice
(1/5)
1. What is the main purpose of data drift detection in MLOps?
easy
A. To reduce the size of the dataset
B. To check if new data differs significantly from the training data
C. To improve the speed of model training
D. To increase the number of features in the model
Solution
Step 1: Understand data drift concept
Data drift means the new data changes compared to the data used to train the model.
Step 2: Identify the purpose of detection
Detecting data drift helps decide when to retrain or update the model to keep it accurate.
Final Answer:
To check if new data differs significantly from the training data -> Option B
Quick Check:
Data drift detection = check data difference [OK]
Hint: Data drift means new data changes from old data [OK]
Common Mistakes:
Confusing data drift with model speed optimization
Thinking data drift reduces dataset size
Assuming data drift adds features
2. Which Python library is commonly used for detecting data drift in MLOps?
easy
A. Flask
B. NumPy
C. Matplotlib
D. Evidently
Solution
Step 1: Recall common MLOps tools
Evidently is a popular tool designed specifically for monitoring data and model drift.
Step 2: Differentiate from other libraries
NumPy is for math, Matplotlib for plotting, Flask for web apps, not for drift detection.
Final Answer:
Evidently -> Option D
Quick Check:
Evidently = data drift detection tool [OK]
Hint: Evidently is made for data drift detection [OK]
Common Mistakes:
Choosing NumPy or Matplotlib which are not for drift detection
Confusing Flask as a data tool
3. Given the code snippet using Evidently, what will report.run(reference_data, current_data) do?
medium
A. Visualize the model architecture
B. Train a new model on current_data
C. Compare current_data with reference_data to detect data drift
D. Delete old data from the system
Solution
Step 1: Understand Evidently report usage
The run method compares new data (current_data) against reference data to find differences.
Step 2: Identify the purpose of the method
It does not train models, visualize architecture, or delete data; it detects data drift.
Final Answer:
Compare current_data with reference_data to detect data drift -> Option C
Quick Check:
report.run compares data for drift [OK]
Hint: report.run compares new vs reference data [OK]
Common Mistakes:
Thinking it trains a model
Assuming it visualizes model structure
Believing it deletes data
4. You wrote this code to detect data drift but get an error:
from evidently.dashboard import Dashboard
dashboard = Dashboard(tabs=["data_drift"])
dashboard.run(current_data)
What is the likely mistake?
medium
A. Missing reference data argument in dashboard.run()
B. Incorrect import statement for Dashboard
C. Dashboard does not support data_drift tab
D. current_data is not a valid variable name
Solution
Step 1: Check Dashboard.run() method requirements
Dashboard.run() requires both reference and current datasets to compare for drift.
Step 2: Identify missing argument
Only current_data is passed; reference_data is missing, causing the error.
Final Answer:
Missing reference data argument in dashboard.run() -> Option A
Quick Check:
Dashboard.run needs reference and current data [OK]
Hint: Dashboard.run needs two datasets: reference and current [OK]
Common Mistakes:
Assuming import is wrong
Thinking data_drift tab is unsupported
Believing variable name causes error
5. You want to automate retraining your model when data drift is detected. Which approach best fits this goal?
hard
A. Set up a monitoring pipeline that runs data drift detection daily and triggers retraining if drift is found
B. Retrain the model every week regardless of data changes
C. Manually check data drift reports and retrain when you have time
D. Ignore data drift and only retrain when model accuracy drops
Solution
Step 1: Understand automation in MLOps
Automating retraining based on data drift ensures the model stays accurate without manual checks.
Step 2: Identify best practice
Running daily drift detection and triggering retraining only when drift occurs is efficient and effective.
Final Answer:
Set up a monitoring pipeline that runs data drift detection daily and triggers retraining if drift is found -> Option A
Quick Check:
Automate retrain on drift detection = best practice [OK]
Hint: Automate retrain triggered by drift detection [OK]