Practice
1. What does the following Python code output when computing the ROC curve?
from sklearn.metrics import roc_curve
import numpy as np
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
print(fpr, tpr, thresholds)easy
Solution
Step 1: Understand ROC curve output
The ROC curve function returns false positive rates (fpr), true positive rates (tpr), and thresholds.Step 2: Analyze the code
Given the scores and true labels, the ROC curve is calculated correctly, resulting in fpr, tpr, and thresholds as in array([0. , 0.5, 1. ]), array([0. , 0.5, 1. ]), array([0.8, 0.35, 0.1]).Final Answer:
Option C -> Option CQuick Check:
ROC curve outputs fpr, tpr, thresholds [OK]
Hint: ROC curve outputs fpr, tpr, thresholds [OK]
Common Mistakes:
2. You implemented early stopping in your training loop, but the model still overfits. What is the most likely reason?
medium
Solution
Step 1: Analyze early stopping behavior
Early stopping relies on validation performance to halt training.Step 2: Identify the root cause of overfitting
If the validation set is too small, it may not accurately reflect generalization, leading to overfitting despite early stopping.Final Answer:
Option A -> Option AQuick Check:
Small validation set can mislead early stopping. [OK]
Hint: Small validation set can mislead early stopping. [OK]
Common Mistakes:
3. In your implementation of K-Means, the algorithm is not converging. What is the most likely cause?
medium
Solution
Step 1: Identify convergence issues
Poorly chosen initial centroids can lead to non-convergence as they may not represent the data well.Step 2: Eliminate wrong options
The number of clusters is too large. is incorrect because a large number of clusters doesn't prevent convergence. The dataset is too small. is incorrect as a small dataset doesn't inherently cause non-convergence. The distance metric is incorrect. is incorrect if the metric is consistent.Final Answer:
Option C -> Option CQuick Check:
Check initial centroids for convergence issues. [OK]
Hint: Check initial centroids for convergence issues. [OK]
Common Mistakes:
4. How can you optimize the backward pass of batch normalization to improve computational efficiency?
hard
Solution
Step 1: Identify optimization techniques
Fusing operations can reduce computational overhead.Step 2: Evaluate each option
Fusing batch normalization with linear layers reduces redundant computations.Final Answer:
Option A -> Option AQuick Check:
Fuse layers to optimize batch norm [OK]
Hint: Fuse layers to optimize batch norm [OK]
Common Mistakes:
5. How can you optimize the memory usage of the Skip-Gram model with negative sampling when dealing with a large vocabulary?
hard
Solution
Step 1: Identify memory bottlenecks
Large vocabularies lead to large embedding matrices, consuming significant memory.Step 2: Evaluate optimization strategies
Sparse embeddings store only non-zero entries, significantly reducing memory usage compared to dense matrices.Final Answer:
Option B -> Option BQuick Check:
Sparse embeddings save memory for large vocabularies [OK]
Hint: Sparse embeddings save memory for large vocabularies [OK]
Common Mistakes:
