Practice
1. What does the following Python code snippet output when implementing the forward pass of batch normalization?
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
mean = np.mean(X, axis=0)
var = np.var(X, axis=0)
X_norm = (X - mean) / np.sqrt(var + 1e-8)
print(X_norm)easy
Solution
Step 1: Understand the code
The code calculates the mean and variance for each feature, normalizes the data, and prints it.Step 2: Check the normalization
Batch normalization ensures each feature has zero mean and unit variance.Final Answer:
Option C -> Option CQuick Check:
Batch norm: zero mean, unit variance [OK]
Hint: Batch norm: zero mean, unit variance [OK]
Common Mistakes:
2. What is the time complexity of calculating the entropy for a dataset with n samples?
easy
Solution
Step 1: Analyze entropy calculation
Entropy calculation involves counting occurrences and computing probabilities, both O(n).Step 2: Eliminate wrong options
O(n^2) and O(n log n) are incorrect as they overestimate the operations needed.Final Answer:
Option D -> Option DQuick Check:
Entropy calculation is linear in n [OK]
Hint: Entropy calculation is linear in n [OK]
Common Mistakes:
3. What is the time complexity of the following non-max suppression implementation?
def non_max_suppression(boxes, scores, iou_threshold):
indices = np.argsort(scores)[::-1]
keep = []
while len(indices) > 0:
current = indices[0]
keep.append(current)
indices = indices[1:]
indices = [i for i in indices if iou(boxes[current], boxes[i]) < iou_threshold]
return keepeasy
Solution
Step 1: Analyze the loop structure
The outer loop runs n times, and the inner loop (IoU calculation) also runs n times in the worst case.Step 2: Determine complexity
Each IoU calculation is O(1), making the overall complexity O(n^2).Final Answer:
Option B -> Option BQuick Check:
Nested loops suggest O(n^2) [OK]
Hint: Nested loops suggest O(n^2) [OK]
Common Mistakes:
4. 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:
5. 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:
