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. 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:
3.
import numpy as np
confusion_matrix = np.array([[50, 10], [5, 35]])
precision = confusion_matrix[0, 0] / (confusion_matrix[0, 0] + confusion_matrix[1, 0])
recall = confusion_matrix[0, 0] / (confusion_matrix[0, 0] + confusion_matrix[0, 1])
print(f"Precision: {precision}, Recall: {recall}")easy
Solution
Step 1: Calculate Precision
Precision is calculated as TP / (TP + FP) = 50 / (50 + 5) = 0.9091.Step 2: Calculate Recall
Recall is calculated as TP / (TP + FN) = 50 / (50 + 10) = 0.8333.Final Answer:
Option D -> Option DQuick Check:
Precision uses FP, Recall uses FN. [OK]
Hint: Precision uses FP, Recall uses FN. [OK]
Common Mistakes:
4. A Gaussian Naive Bayes model is giving poor performance on a dataset. Which of the following is the most likely cause?
medium
Solution
Step 1: Identify Gaussian Naive Bayes assumptions
Gaussian Naive Bayes assumes that features are normally distributed.Step 2: Evaluate each option
The features are not normally distributed. is correct because non-normal distribution violates the model's assumptions. The model has too many parameters. is incorrect as GaussianNB is simple. The dataset is too small. is less likely as small datasets affect all models. The features are highly correlated. is incorrect as GaussianNB can handle correlated features.Final Answer:
Option B -> Option BQuick Check:
GaussianNB assumes normal distribution. [OK]
Hint: GaussianNB assumes normal distribution. [OK]
Common Mistakes:
5. How can you optimize the computation of the ROC curve for a large dataset?
hard
Solution
Step 1: Identify optimization strategies
Parallel processing can speed up computation by handling different thresholds simultaneously.Step 2: Eliminate wrong options
Use a smaller batch size for computation. doesn't address the core computation, Use a subset of data to approximate the ROC curve. may reduce accuracy, Use a more efficient sorting algorithm for the scores. is limited by sorting algorithm constraints.Final Answer:
Option D -> Option DQuick Check:
Parallel processing speeds up ROC computation [OK]
Hint: Parallel processing speeds up ROC computation [OK]
Common Mistakes:
