Bird
Raised Fist0
ML Pythonml~20 mins

A/B testing models in ML Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
A/B Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of A/B Testing in Machine Learning
What is the main goal of performing A/B testing when comparing two machine learning models?
ATo determine which model performs better on a specific metric using real user data
BTo combine the predictions of both models to improve accuracy
CTo train both models on the same dataset simultaneously
DTo reduce the size of the training dataset by splitting it
Attempts:
2 left
💡 Hint
Think about how A/B testing helps in decision making with live data.
❓ Predict Output
intermediate
2:00remaining
Output of A/B Test Metric Calculation
Given the following Python code that calculates conversion rates for two models in an A/B test, what is the printed output?
ML Python
model_a_conversions = 120
model_a_visitors = 1000
model_b_conversions = 150
model_b_visitors = 1200

conversion_rate_a = model_a_conversions / model_a_visitors
conversion_rate_b = model_b_conversions / model_b_visitors

print(f"Model A Conversion Rate: {conversion_rate_a:.3f}")
print(f"Model B Conversion Rate: {conversion_rate_b:.3f}")
A
Model A Conversion Rate: 0.120
Model B Conversion Rate: 0.125
B
Model A Conversion Rate: 0.125
Model B Conversion Rate: 0.120
C
Model A Conversion Rate: 0.012
Model B Conversion Rate: 0.015
D
Model A Conversion Rate: 1.200
Model B Conversion Rate: 1.250
Attempts:
2 left
💡 Hint
Conversion rate is conversions divided by visitors.
❓ Hyperparameter
advanced
2:00remaining
Choosing Sample Size for A/B Testing
Which factor is most important when deciding the sample size for an A/B test comparing two machine learning models?
AThe number of layers in the neural network
BThe number of features in the dataset
CThe expected difference in performance between the two models
DThe training time of the models
Attempts:
2 left
💡 Hint
Think about what affects the ability to detect a difference in results.
❓ Metrics
advanced
2:00remaining
Interpreting A/B Test Results with Confidence Intervals
If the 95% confidence interval for the difference in conversion rates between Model B and Model A is [-0.01, 0.03], what can you conclude?
AModel B is significantly better than Model A
BThere is no statistically significant difference between the models
CModel A is significantly better than Model B
DThe test was invalid due to overlapping intervals
Attempts:
2 left
💡 Hint
Check if zero is inside the confidence interval.
🔧 Debug
expert
3:00remaining
Identifying the Bug in A/B Test Data Split Code
What error will this Python code raise when splitting data for an A/B test, and why? code: import numpy as np users = np.array([1,2,3,4,5,6,7,8,9,10]) np.random.seed(42) mask = np.random.rand(len(users)) > 0.5 ab_test_group = users[mask] control_group = users[~mask] print(f"A/B Test Group: {ab_test_group}") print(f"Control Group: {control_group}") print(f"Total users: {len(ab_test_group) + len(control_group)}")
AIndexError because mask contains values outside valid index range
BTypeError because mask is not a boolean array
CValueError because the mask length does not match users length
DNo error; the total users printed will be 10
Attempts:
2 left
💡 Hint
Check the type and length of the mask array.

Practice

(1/5)
1. What is the main purpose of A/B testing models in machine learning?
easy
A. To compare two models by testing them on separate groups
B. To train a single model on all data
C. To reduce the size of the dataset
D. To increase the number of features in the model

Solution

  1. Step 1: Understand the goal of A/B testing

    A/B testing is used to compare two different models or versions by testing them separately.
  2. Step 2: Identify the correct purpose

    The purpose is to find which model performs better by testing on separate groups, not to train on all data or change dataset size.
  3. Final Answer:

    To compare two models by testing them on separate groups -> Option A
  4. Quick Check:

    A/B testing = compare models [OK]
Hint: A/B testing means comparing two models on different groups [OK]
Common Mistakes:
  • Thinking A/B testing trains one model on all data
  • Confusing A/B testing with feature engineering
  • Believing A/B testing reduces dataset size
2. Which of the following is the correct way to split data for A/B testing?
easy
A. Train both models on the entire dataset simultaneously
B. Use the same data for both models without splitting
C. Split data randomly into two groups and test each model separately
D. Split data by sorting values and assigning first half to model A

Solution

  1. Step 1: Recall proper data splitting for A/B testing

    Data should be split randomly to avoid bias and ensure fair comparison.
  2. Step 2: Evaluate options

    Only random splitting into two groups is correct; using same data or sorted split causes bias.
  3. Final Answer:

    Split data randomly into two groups and test each model separately -> Option C
  4. Quick Check:

    Random split = fair test [OK]
Hint: Always split data randomly for fair A/B testing [OK]
Common Mistakes:
  • Using same data for both models
  • Splitting data by sorting values
  • Training both models on full data
3. Consider this Python code for A/B testing two models on separate data splits:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

X = [[1], [2], [3], [4], [5], [6]]
y = [0, 0, 0, 1, 1, 1]

X_train_A, X_test_A, y_train_A, y_test_A = train_test_split(X[:3], y[:3], test_size=1, random_state=42)
X_train_B, X_test_B, y_train_B, y_test_B = train_test_split(X[3:], y[3:], test_size=1, random_state=42)

model_A = LogisticRegression().fit(X_train_A, y_train_A)
model_B = LogisticRegression().fit(X_train_B, y_train_B)

pred_A = model_A.predict(X_test_A)
pred_B = model_B.predict(X_test_B)

acc_A = accuracy_score(y_test_A, pred_A)
acc_B = accuracy_score(y_test_B, pred_B)

print(acc_A, acc_B)

What will be the printed output?
medium
A. 0.0 0.0
B. 1.0 1.0
C. 1.0 0.0
D. 0.0 1.0

Solution

  1. Step 1: Analyze data splits and training

    Each model trains on 2 samples and tests on 1 sample. The test samples are [3] for A and [6] for B with labels 0 and 1 respectively.
  2. Step 2: Predict and calculate accuracy

    LogisticRegression will perfectly separate these simple points, so predictions match true labels, giving accuracy 1.0 for both.
  3. Final Answer:

    1.0 1.0 -> Option B
  4. Quick Check:

    Perfect split and simple data = accuracy 1.0 [OK]
Hint: Small simple splits often give perfect accuracy [OK]
Common Mistakes:
  • Assuming accuracy is zero due to small data
  • Confusing train and test splits
  • Ignoring random_state effect
4. You run an A/B test comparing two models but notice both groups have very different user ages. What is the likely problem?
medium
A. Data was not split randomly, causing bias
B. Models are overfitting the training data
C. Test size was too large
D. Models have too many features

Solution

  1. Step 1: Identify issue from uneven user ages

    Unequal age distribution means groups are not similar, indicating non-random splitting.
  2. Step 2: Understand impact on A/B testing

    Non-random splits cause bias, making test results unreliable.
  3. Final Answer:

    Data was not split randomly, causing bias -> Option A
  4. Quick Check:

    Unequal groups = non-random split [OK]
Hint: Unequal groups mean split was not random [OK]
Common Mistakes:
  • Blaming overfitting for group differences
  • Thinking test size causes group bias
  • Confusing feature count with data split
5. You want to run an A/B test comparing two recommendation models on a website. Which approach best ensures a fair test?
hard
A. Assign users based on their signup date to different models
B. Show both models to all users and average their recommendations
C. Train both models on the same user data and pick the one with higher training accuracy
D. Randomly assign users to Model A or Model B groups and collect click data separately

Solution

  1. Step 1: Understand fair A/B testing for users

    Random assignment ensures groups are similar and results are unbiased.
  2. Step 2: Evaluate other options

    Showing both models to all users or assigning by signup date causes bias; training accuracy alone is not enough.
  3. Final Answer:

    Randomly assign users to Model A or Model B groups and collect click data separately -> Option D
  4. Quick Check:

    Random user assignment = fair A/B test [OK]
Hint: Random user assignment ensures unbiased A/B test [OK]
Common Mistakes:
  • Showing both models to same users
  • Using signup date for group assignment
  • Choosing model by training accuracy only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard