Practice
1. What is the time complexity of updating the learning rate using PyTorch's
StepLR scheduler for each epoch?easy
Solution
Step 1: Analyze StepLR update mechanism
StepLR updates the learning rate by multiplying it with a constant factor, which is a constant time operation.Step 2: Determine time complexity
Since the update is a simple multiplication, the time complexity is O(1).Final Answer:
Option C -> Option CQuick Check:
StepLR update is a constant time operation. [OK]
Hint: StepLR update is a constant time operation. [OK]
Common Mistakes:
2. 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:
3. Your mAP implementation is returning unusually high values. What is the most likely cause?
medium
Solution
Step 1: Identify the Symptom
High mAP values suggest too many matches are considered correct.Step 2: Analyze Each Option
Incorrect IoU threshold for positive matches: A low IoU threshold can cause false positives to be counted as true positives, inflating mAP. Using precision instead of recall in calculations: Would affect recall, not mAP directly. Not normalizing the precision values: Would affect the scale, not the value. Including false negatives in the precision calculation: Would lower precision, not increase it.Final Answer:
Option B -> Option BQuick Check:
Check IoU threshold for false positives [OK]
Hint: Check IoU threshold for false positives [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.
def calculate_f1(confusion_matrix):
tp = confusion_matrix[0, 0]
fp = confusion_matrix[1, 0]
fn = confusion_matrix[0, 1]
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1_score = 2 * (precision * recall) / (precision + recall)
return f1_score
confusion_matrix = np.array([[50, 10], [5, 35]])
print(calculate_f1(confusion_matrix))medium
Solution
Step 1: Calculate precision and recall
Precision = 0.9091, Recall = 0.8333.Step 2: Calculate F1-score
F1 = 2 * (0.9091 * 0.8333) / (0.9091 + 0.8333) = 0.8696.Final Answer:
Option B -> Option BQuick Check:
F1 combines precision and recall. [OK]
Hint: F1 combines precision and recall. [OK]
Common Mistakes:
