Practice
1. What is the time complexity of computing a confusion matrix for a binary classification problem with n predictions?
easy
Solution
Step 1: Analyze the operation
Computing a confusion matrix involves iterating over predictions once.Step 2: Determine complexity
Each prediction is checked once, leading to O(n) complexity.Final Answer:
Option C -> Option CQuick Check:
Confusion matrix computation is linear in predictions. [OK]
Hint: Confusion matrix computation is linear in predictions. [OK]
Common Mistakes:
2.
import numpy as np
class DropoutLayer:
def __init__(self, dropout_rate):
self.dropout_rate = dropout_rate
def forward(self, inputs, training=True):
if training:
self.mask = np.random.binomial(1, 1 - self.dropout_rate, size=inputs.shape)
return inputs * self.mask
else:
return inputs
inputs = np.array([1.0, 2.0, 3.0])
dropout_layer = DropoutLayer(0.5)
output = dropout_layer.forward(inputs, training=False)
print(output)easy
Solution
Step 1: Understand Inference Mode
During inference, dropout is not applied, so the input is returned unchanged.Step 2: Eliminate Wrong Options
[0.5, 1.0, 1.5] applies scaling, which is incorrect for inference. [0.0, 0.0, 0.0] assumes all zeros, which is not the case. [2.0, 4.0, 6.0] doubles the input, which is incorrect.Final Answer:
Option B -> Option BQuick Check:
Inference mode returns inputs unchanged. [OK]
Hint: Inference mode returns inputs unchanged. [OK]
Common Mistakes:
3.
import numpy as np
def dcg_at_k(r, k):
r = np.asfarray(r)[:k]
if r.size:
return np.sum(r / np.log2(np.arange(2, r.size + 2)))
return 0.0
relevance_scores = [3, 2, 3, 0, 1, 2]
k = 3
print(dcg_at_k(relevance_scores, k))What does this code output?easy
Solution
Step 1: Understand DCG Calculation
The DCG is calculated as the sum of relevance scores divided by log base 2 of their positions.Step 2: Calculate for k=3
For k=3, the scores are [3, 2, 3]. The calculation is 3/1 + 2/log2(3) + 3/log2(4).Final Answer:
Option A -> Option AQuick Check:
DCG uses log2 positions. [OK]
Hint: DCG uses log2 positions. [OK]
Common Mistakes:
4. 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:
5. How can you optimize the following non-max suppression code for large datasets?
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 keephard
Solution
Step 1: Identify bottleneck
IoU calculations are the most computationally expensive part.Step 2: Optimize bottleneck
Parallelizing IoU calculations can significantly reduce runtime for large datasets.Final Answer:
Option A -> Option AQuick Check:
Parallelize expensive operations [OK]
Hint: Parallelize expensive operations [OK]
Common Mistakes:
