Practice
1.
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 = [1, 1, 3, 3]
box2 = [2, 2, 4, 4]
print(iou(box1, box2))easy
Solution
Step 1: Calculate intersection and union areas
Intersection area is 1, union area is 7.Step 2: Compute IoU
IoU = 1/7 = 0.14285714285714285.Final Answer:
Option C -> Option CQuick Check:
Intersection over Union formula [OK]
Hint: Intersection over Union formula [OK]
Common Mistakes:
2. What is the time complexity of computing the softmax function for an input array of size n?
easy
Solution
Step 1: Analyze operations
Softmax involves computing exponentials and a sum, both linear in n.Step 2: Determine complexity
Each operation is O(n), so overall complexity is O(n).Final Answer:
Option D -> Option DQuick Check:
Softmax is linear in input size [OK]
Hint: Softmax is linear in input size [OK]
Common Mistakes:
3. In a decision tree, how would you handle a dataset with continuous features?
medium
Solution
Step 1: Consider handling continuous features
Discretizing into bins allows decision trees to handle continuous data effectively.Step 2: Eliminate wrong options
One-hot encoding (A) is for categorical data; ignoring (C) loses information; using directly (D) can lead to overfitting.Final Answer:
Option C -> Option CQuick Check:
Continuous? Discretize into bins [OK]
Hint: Continuous? Discretize into bins [OK]
Common Mistakes:
4. You need to apply non-max suppression on a batch of images. Which approach is most efficient?
medium
Solution
Step 1: Consider independence of images
Each image's boxes are independent, so process them separately.Step 2: Evaluate efficiency
Concatenating boxes would mix unrelated data, and focusing on one image or thresholding scores misses other valid boxes.Final Answer:
Option A -> Option AQuick Check:
Process each image independently [OK]
Hint: Process each image independently [OK]
Common Mistakes:
5. In the context of implementing linear regression with gradient descent, how would you handle a dataset with missing values?
medium
Solution
Step 1: Consider impact of missing values
Ignoring or zero-filling can bias results; removing samples reduces data.Step 2: Choose appropriate imputation
Mean imputation is a common strategy that maintains dataset size and reduces bias.Final Answer:
Option A -> Option AQuick Check:
Mean imputation balances bias and data retention. [OK]
Hint: Mean imputation balances bias and data retention. [OK]
Common Mistakes:
