Practice
1. What does the following Python code snippet output when calculating the Intersection over Union (IoU) for two bounding boxes?
import numpy as np
def iou(box1, box2):
x1 = max(box1[0], box2[0])
y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2])
y2 = min(box1[3], box2[3])
intersection = max(0, x2 - x1) * max(0, y2 - y1)
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
union = area1 + area2 - intersection
return intersection / union
box1 = [0, 0, 2, 2]
box2 = [1, 1, 3, 3]
print(iou(box1, box2))easy
Solution
Step 1: Calculate Intersection and Union
The intersection area is 1 (from (1,1) to (2,2)). The union area is 7 (4 from box1 + 4 from box2 - 1 intersection).Step 2: Calculate IoU
IoU = 1/7 = 0.14285714285714285.Final Answer:
Option A -> Option AQuick Check:
Intersection over Union formula [OK]
Hint: Intersection over Union formula [OK]
Common Mistakes:
2. A batch normalization implementation is producing NaN values during training. What is the most likely cause?
medium
Solution
Step 1: Identify the role of epsilon
Epsilon prevents division by zero in variance normalization.Step 2: Analyze NaN causes
NaN values often result from division by zero, indicating a missing or too-small epsilon.Final Answer:
Option B -> Option BQuick Check:
NaN in batch norm? Check epsilon [OK]
Hint: NaN in batch norm? Check epsilon [OK]
Common Mistakes:
3. In which scenario is gradient checking most useful?
medium
Solution
Step 1: Identify scenarios where gradient checking is applicable
Gradient checking is crucial when implementing new components to ensure correctness.Step 2: Eliminate unrelated scenarios
Options A, C, and D are not directly related to verifying gradient correctness.Final Answer:
Option A -> Option AQuick Check:
Use gradient check for new components. [OK]
Hint: Use gradient check for new components. [OK]
Common Mistakes:
4. In a recommendation system, why might you choose NDCG over precision at k?
medium
Solution
Step 1: Understand NDCG vs Precision
NDCG accounts for the position of relevant items, giving higher scores to relevant items at higher ranks.Step 2: Evaluate Options
Precision at k does not consider the order of items, only their presence.Final Answer:
Option B -> Option BQuick Check:
NDCG values position. [OK]
Hint: NDCG values position. [OK]
Common Mistakes:
5. In a PCA implementation, you need to project data onto the first two principal components. Which approach is correct?
medium
Solution
Step 1: Understand projection in PCA
Projection involves multiplying the data matrix by the eigenvectors corresponding to the desired components.Step 2: Eliminate wrong options
Multiply the data matrix by the first two eigenvalues. is incorrect because eigenvalues are not used for projection. Multiply the covariance matrix by the first two eigenvectors. and D incorrectly use the covariance matrix instead of the data matrix.Final Answer:
Option A -> Option AQuick Check:
Project data using eigenvectors, not eigenvalues. [OK]
Hint: Project data using eigenvectors, not eigenvalues. [OK]
Common Mistakes:
