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. A model trained with weak supervision is underperforming. What is the most likely cause?
medium
Solution
Step 1: Identify the weak supervision challenge.
Weak supervision relies on heuristics, which can be a source of error if too simplistic.Step 2: Eliminate other causes.
Model complexity and dataset size are less likely to be the primary issue in weak supervision. Learning rate affects training stability, not heuristic quality.Final Answer:
Option A -> Option AQuick Check:
Weak supervision = heuristic quality [OK]
Hint: Weak supervision = heuristic quality [OK]
Common Mistakes:
3. You need to develop a model to recommend products to users based on their past behavior. Which learning approach is most suitable?
medium
Solution
Step 1: Identify the goal.
The goal is to optimize recommendations over time based on user feedback.Step 2: Eliminate wrong options.
Supervised learning, because it can predict future purchases. is incorrect because predicting purchases doesn't optimize over time. Unsupervised learning, because it can cluster users with similar behaviors. is incorrect because clustering doesn't adapt to feedback. Supervised learning, because it can classify users into categories. is incorrect because classification doesn't optimize recommendations.Final Answer:
Option A -> Option AQuick Check:
Optimize over time -> Reinforcement learning [OK]
Hint: Optimize over time -> Reinforcement learning [OK]
Common Mistakes:
4. A high-dimensional dataset is causing a model to perform poorly. The model's accuracy is unexpectedly low. What is the most likely root cause?
medium
Solution
Step 1: Identify the impact of high dimensions.
High dimensions often lead to data sparsity, affecting generalization.Step 2: Eliminate wrong options.
The model is underfitting due to insufficient complexity. is about model complexity, not data sparsity. The model is overfitting due to too many parameters. is about overfitting, not generalization. The learning rate is too high, causing unstable training. is about training stability, not generalization.Final Answer:
Option A -> Option AQuick Check:
High dimensions lead to sparsity, hurting generalization. [OK]
Hint: High dimensions lead to sparsity, hurting generalization. [OK]
Common Mistakes:
5. In a real-time prediction system, how should you handle data splits to ensure both model performance and system efficiency?
hard
Solution
Step 1: Consider real-time constraints
Real-time systems need to adapt to new data while maintaining performance.Step 2: Evaluate options for adaptability and efficiency
Use a single train-test split to minimize latency. risks overfitting. Use a large test set to ensure model robustness. misallocates resources. Use a static validation set to simplify the system. lacks adaptability to new data.Final Answer:
Option D -> Option DQuick Check:
Rolling window adapts to new data efficiently. [OK]
Hint: Rolling window adapts to new data efficiently. [OK]
Common Mistakes:
