Practice
1.
import numpy as np
y_true = np.array([3, -0.5, 2, 7])
y_pred = np.array([2.5, 0.0, 2, 8])
mae = np.mean(np.abs(y_true - y_pred))
print(mae)What is the output of this code snippet?easy
Solution
Step 1: Calculate the absolute errors.
Errors are [0.5, 0.5, 0, 1].Step 2: Compute the mean of absolute errors.
Mean is (0.5 + 0.5 + 0 + 1) / 4 = 0.625.Final Answer:
Option A -> Option AQuick Check:
Sum errors, divide by count. [OK]
Hint: Sum absolute errors, divide by count. [OK]
Common Mistakes:
2. A reinforcement learning model is not improving its performance despite extensive training. What is the most likely cause?
medium
Solution
Step 1: Identify the issue.
In reinforcement learning, a poorly defined reward function can lead to suboptimal learning.Step 2: Eliminate wrong options.
The model has too many parameters. is incorrect because parameter count affects complexity, not learning direction. The training data is not labeled. is irrelevant as RL doesn't require labeled data. The model is overfitting to the training data. is less likely as overfitting would show initial improvement.Final Answer:
Option D -> Option DQuick Check:
Poor reward function -> Poor learning [OK]
Hint: Poor reward function -> Poor learning [OK]
Common Mistakes:
3. How would you adapt K-Fold cross-validation for a dataset with a temporal component and class imbalance?
hard
Solution
Step 1: Address both temporal order and class imbalance.
Time Series Split respects temporal order, and manual balancing addresses class imbalance.Step 2: Eliminate wrong options.
Standard K-Fold (A) ignores temporal order, Stratified K-Fold (B) doesn't respect temporal order, Leave-One-Out (D) is computationally expensive and doesn't address temporal order.Final Answer:
Option D -> Option DQuick Check:
Time series + imbalance = manual balance. [OK]
Hint: Time series + imbalance = manual balance. [OK]
Common Mistakes:
4. You are tasked with designing a monitoring system for an ML model in production. Which approach ensures robust detection of both data drift and performance decay?
hard
Solution
Step 1: Identify comprehensive monitoring strategies
Combining statistical tests with performance metrics covers both drift and decay.Step 2: Eliminate wrong options
Implement a feedback loop using user satisfaction surveys. is subjective and indirect. Rely solely on periodic model retraining. is reactive, not proactive. Monitor only the model's prediction confidence scores. is too narrow in scope.Final Answer:
Option B -> Option BQuick Check:
Combine stats and metrics for full coverage [OK]
Hint: Combine stats and metrics for full coverage [OK]
Common Mistakes:
5. You need to sample data from a large dataset where some entries are more important than others, and the dataset is too large to fit into memory. Which sampling strategy should you use?
hard
Solution
Step 1: Identify the need for prioritization.
When some entries are more important, prioritization is key.Step 2: Eliminate non-prioritization strategies.
Random (A) and Stratified (B) don't prioritize. Reservoir (C) handles size but not importance.Final Answer:
Option D -> Option DQuick Check:
Weighted = Prioritize important data [[check]]
Hint: Weighted = Prioritize important data [[check]]
Common Mistakes:
