0
0
MLOpsdevops~30 mins

Data drift detection basics in MLOps - Mini Project: Build & Apply

Choose your learning style9 modes available
Data drift detection basics
📖 Scenario: You work as a machine learning engineer. Your model uses data from sensors to predict equipment failures. Over time, the data can change, which may reduce model accuracy. This change is called data drift. Detecting data drift early helps keep the model reliable.
🎯 Goal: Build a simple Python script that detects data drift by comparing the distribution of new sensor data with the original training data.
📋 What You'll Learn
Create a dictionary called training_data with sensor readings as keys and their counts as values
Create a dictionary called new_data with sensor readings as keys and their counts as values
Create a variable called drift_threshold set to 0.2 (20%)
Calculate the total counts in training_data and new_data
Use a for loop with variables reading and count to iterate over training_data.items()
Calculate the proportion difference for each reading between training_data and new_data
Detect if any proportion difference exceeds drift_threshold
Print "Data drift detected" if drift is found, otherwise print "No data drift detected"
💡 Why This Matters
🌍 Real World
Detecting data drift helps maintain machine learning model accuracy by alerting engineers when input data changes significantly.
💼 Career
Data scientists and MLOps engineers use data drift detection to monitor models in production and trigger retraining or alerts.
Progress0 / 4 steps
1
Create the training data dictionary
Create a dictionary called training_data with these exact entries: "temp_high": 50, "temp_normal": 150, "temp_low": 30
MLOps
Need a hint?

Use curly braces {} to create a dictionary with keys and values.

2
Create the new data dictionary and drift threshold
Create a dictionary called new_data with these exact entries: "temp_high": 100, "temp_normal": 90, "temp_low": 40. Then create a variable called drift_threshold and set it to 0.2
MLOps
Need a hint?

Remember to use the exact variable names and values given.

3
Calculate proportions and detect drift
Calculate the total counts in training_data and new_data using sum(). Then use a for loop with variables reading and count to iterate over training_data.items(). Inside the loop, calculate the proportion of each reading in training_data and new_data. Check if the absolute difference between these proportions is greater than drift_threshold. If yes, set a variable drift_detected to True.
MLOps
Need a hint?

Use new_data.get(reading, 0) to safely get counts from new_data.

4
Print the drift detection result
Write a print statement that prints "Data drift detected" if drift_detected is True. Otherwise, print "No data drift detected".
MLOps
Need a hint?

Use an if statement to check drift_detected and print the correct message.