Practice
1. Given the following Python code, what will be the output?
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(len(X_train), len(X_test))easy
Solution
Step 1: Calculate the split sizes
With a test_size of 0.2, 20% of 10 samples go to the test set, i.e., 2 samples.Step 2: Determine the training set size
The remaining 80% (8 samples) go to the training set.Final Answer:
Option B -> Option BQuick Check:
80% train, 20% test split. [OK]
Hint: 80% train, 20% test split. [OK]
Common Mistakes:
2. When comparing two ML models using A/B testing, why might you choose causal inference over the holdout method?
medium
Solution
Step 1: Understand the methods
Causal inference helps understand the cause-effect relationship, not just performance.Step 2: Eliminate wrong options
Holdout is not inherently less accurate or unsuitable for large datasets. Causal inference is not necessarily faster.Final Answer:
Option C -> Option CQuick Check:
Causal inference explains why, not just what. [OK]
Hint: Causal inference explains why, not just what. [OK]
Common Mistakes:
3. When choosing between K-Means and Gaussian Mixture Models (GMM) for clustering, which scenario favors K-Means?
medium
Solution
Step 1: Compare K-Means and GMM
K-Means assumes spherical clusters with similar variance, while GMM can handle different shapes and densities.Step 2: Identify the scenario
Clusters with similar variance and spherical shape describes clusters with similar variance and spherical shape, which is ideal for K-Means.Final Answer:
Option D -> Option DQuick Check:
K-Means loves spherical, similar variance clusters [OK]
Hint: K-Means loves spherical, similar variance clusters [OK]
Common Mistakes:
4. When deciding between offline and online evaluation for a new feature in a web application, which approach is more suitable if user feedback is critical and why?
medium
Solution
Step 1: Identify the need for user feedback.
When user feedback is critical, capturing real interactions is essential.Step 2: Evaluate the suitability of each approach.
Offline evaluation, because it allows for controlled experiments. is incorrect because controlled experiments do not capture real-time feedback. Offline evaluation, because it is faster and less resource-intensive. is incorrect because speed and resource usage do not address feedback needs. Online evaluation, because it avoids overfitting to historical data. is partially correct but does not emphasize feedback.Final Answer:
Option B -> Option BQuick Check:
Real feedback needs online evaluation. [OK]
Hint: Real feedback needs online evaluation. [OK]
Common Mistakes:
5. A model's performance improved significantly on the test set but not on the validation set. What is the most likely cause?
medium
Solution
Step 1: Analyze performance discrepancy
Significant improvement on the test set but not on the validation set suggests an issue with test set integrity.Step 2: Identify data leakage
Data leakage from the test set can artificially inflate performance metrics.Final Answer:
Option A -> Option AQuick Check:
Test set improvement only? Check for leakage [OK]
Hint: Test set improvement only? Check for leakage [OK]
Common Mistakes:
