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
A/B Testing Model Versions
📖 Scenario: You work in a team that deploys machine learning models. You want to compare two versions of a model to see which one performs better in real user traffic. This is called A/B testing.We will simulate a simple A/B test by assigning users to either model version A or B and counting how many users each version serves.
🎯 Goal: Build a simple A/B testing simulation that assigns users to model versions and counts the number of users served by each version.
📋 What You'll Learn
Create a list of user IDs
Define the percentage split for model versions A and B
Assign each user to a model version based on the split
Count how many users are assigned to each model version
Print the counts for both model versions
💡 Why This Matters
🌍 Real World
A/B testing is used in real machine learning deployments to compare different model versions by splitting user traffic and measuring which version performs better.
💼 Career
Understanding A/B testing helps in roles like MLOps engineer, data scientist, and DevOps engineer to safely deploy and evaluate machine learning models in production.
Progress0 / 4 steps
1
Create a list of user IDs
Create a list called user_ids containing these exact user IDs as strings: 'user1', 'user2', 'user3', 'user4', 'user5'.
MLOps
Hint
Use square brackets to create a list and put the user IDs as strings inside.
2
Define the A/B split percentage
Create a variable called ab_split and set it to 0.6 to represent 60% of users assigned to model version A.
MLOps
Hint
Use a simple assignment to create the variable ab_split with the value 0.6.
3
Assign users to model versions
Create a dictionary called assignments that assigns each user in user_ids to either 'A' or 'B'. Assign the first 60% of users to 'A' and the rest to 'B' using a for loop with index i and user user.
MLOps
Hint
Use enumerate to get the index and user. Use int(len(user_ids) * ab_split) to find the cutoff.
4
Count and print users per model version
Create two variables count_A and count_B to count how many users are assigned to model versions 'A' and 'B' respectively. Use a for loop over assignments.values(). Then print the counts exactly as: print(f"Model A users: {count_A}") and print(f"Model B users: {count_B}").
MLOps
Hint
Initialize counts to zero. Loop over assignments.values() and add 1 to the right count. Use f-strings to print.
Practice
(1/5)
1. What is the main purpose of A/B testing in model deployment?
easy
A. To train a model faster using multiple GPUs
B. To compare two model versions by splitting user traffic
C. To backup model data in the cloud
D. To monitor server CPU usage during training
Solution
Step 1: Understand A/B testing concept
A/B testing involves running two versions of a model simultaneously to compare their performance.
Step 2: Identify the main goal
The goal is to split user traffic between two models to see which performs better in real conditions.
Final Answer:
To compare two model versions by splitting user traffic -> Option B
Quick Check:
A/B testing = compare models by traffic split [OK]
Hint: A/B testing means splitting users to compare models [OK]
Common Mistakes:
Confusing A/B testing with training speedup
Thinking it is about data backup
Mixing it with server monitoring
2. Which of the following is the correct way to define a traffic split for A/B testing in YAML?
60% + 50% = 110%, which is more than 100% allowed for traffic split.
Step 2: Understand traffic split constraints
Traffic percentages must sum to exactly 100% to properly split user traffic between models.
Final Answer:
Percentages add up to more than 100% -> Option A
Quick Check:
Sum of percents > 100% is invalid [OK]
Hint: Traffic split percentages must total 100% [OK]
Common Mistakes:
Ignoring total percentage sum
Thinking percentages can be unequal but sum over 100
Confusing syntax error with logic error
5. You want to run an A/B test comparing model versions v1 and v2. You have 10,000 users and want to assign 70% traffic to v1 and 30% to v2. Which approach ensures consistent user assignment and fair metric tracking?
hard
A. Assign users based on hashing their user ID modulo 100 and map to traffic split
B. Assign users manually by checking their signup date
C. Assign all users to v1 for the first week, then switch all to v2
D. Randomly assign users on each request without storing assignment
Solution
Step 1: Understand consistent user assignment need
Users must always get the same model version to avoid confusing metrics and user experience.
Step 2: Evaluate assignment methods
Hashing user ID modulo 100 maps users consistently to a number 0-99, which can be split 70/30 for v1/v2.
Step 3: Reject other options
Random assignment each request causes inconsistency; switching all users breaks A/B test; manual assignment is impractical and biased.
Final Answer:
Assign users based on hashing their user ID modulo 100 and map to traffic split -> Option A