Practice
1.
import numpy as np
# Simulate A/B test results
A_results = np.array([1, 0, 1, 1, 0])
B_results = np.array([0, 1, 0, 0, 1])
# Calculate mean conversion rates
A_mean = np.mean(A_results)
B_mean = np.mean(B_results)
# Determine which variant is better
better_variant = 'A' if A_mean > B_mean else 'B'
print(better_variant)What does this code output?easy
Solution
Step 1: Calculate means
A_mean = 0.6, B_mean = 0.2Step 2: Compare means
A_mean > B_mean, so 'A' is printed.Final Answer:
A -> AQuick Check:
Calculate means, compare, print. [OK]
Hint: Calculate means, compare, print. [OK]
Common Mistakes:
2.
import numpy as np
from sklearn.preprocessing import StandardScaler
X = np.array([[1, 2], [3, 4], [5, 6]])
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled.mean(axis=0))What does this code output?easy
Solution
Step 1: Understand standardization.
StandardScaler standardizes features by removing the mean and scaling to unit variance.Step 2: Calculate the mean of standardized data.
After standardization, the mean of each feature should be 0.Final Answer:
Option C -> Option CQuick Check:
StandardScaler centers data to mean 0. [OK]
Hint: StandardScaler centers data to mean 0. [OK]
Common Mistakes:
3. In the context of why machine learning exists, which of the following problems is most suitable for a machine learning approach rather than a rule-based system?
easy
Solution
Step 1: Identify the nature of the problem.
Predicting the next word in a sentence involves understanding context and patterns, which are complex and not easily defined by rules.Step 2: Eliminate rule-based problems.
Options A, C, and D are deterministic and can be solved with explicit algorithms.Final Answer:
Option A -> Option AQuick Check:
ML for patterns, rules for logic. [OK]
Hint: ML excels at pattern recognition, not deterministic logic. [OK]
Common Mistakes:
4. In a scenario where computational resources are limited, which approach is more suitable for hyperparameter tuning and why?
medium
Solution
Step 1: Evaluate resource constraints
Cross-validation is computationally expensive but provides robust tuning.Step 2: Eliminate less suitable options
Use a single train-test split to save resources. risks overfitting. Use a train-validation split and skip the test set. skips the test set, risking unseen data performance. Use a larger test set to ensure model generalization. misallocates resources to testing rather than tuning.Final Answer:
Option C -> Option CQuick Check:
Cross-validation ensures robust tuning despite cost. [OK]
Hint: Cross-validation ensures robust tuning despite cost. [OK]
Common Mistakes:
5. You need to implement a real-time recommendation system. Which approach is most suitable given the need for low latency and high throughput?
hard
Solution
Step 1: Identify the requirements.
Real-time systems require low latency and high throughput.Step 2: Choose the approach that meets these requirements.
Online learning with a streaming framework allows for real-time updates and low latency.Final Answer:
Option A -> Option AQuick Check:
Streaming fits real-time needs. [OK]
Hint: Streaming fits real-time needs. [OK]
Common Mistakes:
