Practice
1. Given the following Python code snippet, what will be the output if the model is trained with biased data?
from sklearn.metrics import accuracy_score
y_true = [0, 1, 1, 0, 1]
y_pred = [0, 1, 1, 0, 0]
accuracy = accuracy_score(y_true, y_pred)
print(accuracy)easy
Solution
Step 1: Calculate the accuracy.
Accuracy is the ratio of correctly predicted instances to the total instances. Here, 3 out of 5 predictions are correct.Step 2: Compute the accuracy.
Correct predictions: [0, 1, 1] -> 0.6Final Answer:
0.6 -> 0.6Quick Check:
Count correct predictions, divide by total. [OK]
Hint: Count correct predictions, divide by total. [OK]
Common Mistakes:
2. A model performs well on the validation set but poorly on the test set. What is the most likely cause?
medium
Solution
Step 1: Identify the discrepancy
Good validation performance but poor test performance suggests a mismatch between sets.Step 2: Eliminate less likely causes
The model is underfitting the data. is incorrect as underfitting would affect both sets. The validation set is too small. is less likely unless the validation set is extremely small. The model has too many parameters. would likely affect both sets similarly.Final Answer:
Option A -> Option AQuick Check:
Mismatch between validation and test sets. [OK]
Hint: Mismatch between validation and test sets. [OK]
Common Mistakes:
3. A deployed model's performance has suddenly dropped. The training and test data distributions were initially aligned. What is the most likely cause?
medium
Solution
Step 1: Identify the cause of performance drop.
Covariate drift can cause a sudden drop in performance if input distributions change.Step 2: Eliminate wrong options.
Overfitting (The model was overfitted to the training data.) and parameter count (The model has too many parameters.) would affect initial performance. Incorrect scaling (The feature scaling was incorrect.) would cause consistent issues, not sudden drops.Final Answer:
Option A -> Option AQuick Check:
Sudden drop? Check for covariate drift [OK]
Hint: Sudden drop? Check for covariate drift [OK]
Common Mistakes:
4. When should you prefer approximate nearest neighbors over exact KNN?
medium
Solution
Step 1: Consider dataset size and dimensionality
Approximate methods are beneficial for large, high-dimensional datasets.Step 2: Eliminate wrong options
When you have a small dataset with low dimensions. is incorrect as exact KNN is feasible. When you need exact results for a critical application. is wrong because approximate methods are not for critical exactness. When computational resources are unlimited. is incorrect as resources are not a constraint.Final Answer:
Option A -> Option AQuick Check:
Approximate for large, high-dimension data. [OK]
Hint: Approximate for large, high-dimension data. [OK]
Common Mistakes:
5. You need to design a recurrent neural network for a real-time translation system. Which approach would best handle the vanishing gradient problem while maintaining low latency?
hard
Solution
Step 1: Consider latency and vanishing gradient.
GRUs are simpler and faster, reducing latency while handling vanishing gradients.Step 2: Evaluate other options.
Deep LSTM (A) increases latency, standard RNN (C) struggles with gradients, bidirectional LSTM (D) adds complexity and latency.Final Answer:
Option B -> Option BQuick Check:
GRU: fast, handles vanishing gradients. [check]
Hint: GRU: fast, handles vanishing gradients. [check]
Common Mistakes:
