Practice
1.
import numpy as np
def cosine_similarity(a, b):
dot_product = np.dot(a, b)
norm_a = np.linalg.norm(a)
norm_b = np.linalg.norm(b)
return dot_product / (norm_a * norm_b)
vector1 = np.array([1, 2, 3])
vector2 = np.array([4, 5, 6])
result = cosine_similarity(vector1, vector2)
print(result)easy
Solution
Step 1: Calculate dot product and norms
Dot product = 32, norm_a = 3.7416573867739413, norm_b = 8.774964387392123.Step 2: Compute cosine similarity
Cosine similarity = 32 / (3.7416573867739413 * 8.774964387392123) = 0.9746318461970762.Final Answer:
Option A -> Option AQuick Check:
Dot product over product of norms. [OK]
Hint: Dot product over product of norms. [OK]
Common Mistakes:
2.
from sklearn.model_selection import KFold
import numpy as np
X = np.array([1, 2, 3, 4, 5])
kf = KFold(n_splits=2)
for train_index, test_index in kf.split(X):
print("Train:", train_index, "Test:", test_index)
What will be the output of the above code?easy
Solution
Step 1: Understand KFold behavior
KFold splits the data into n_splits parts, here 2, and iterates over them.Step 2: Eliminate wrong options
Train: [0 1 2 3] Test: [4] and Train: [4] Test: [0 1 2 3] and D suggest incorrect split sizes. Train: [0 1] Test: [2 3 4] and Train: [2 3 4] Test: [0 1] suggests incorrect indexing.Final Answer:
Option B -> Option BQuick Check:
KFold splits into equal parts. [OK]
Hint: KFold splits data into equal parts. [OK]
Common Mistakes:
3. What is the time complexity of applying a dropout layer to an input of size n during training?
easy
Solution
Step 1: Analyze Dropout Operation
Applying dropout involves generating a mask and element-wise multiplication, both O(n) operations.Step 2: Eliminate Wrong Options
O(1) suggests constant time, which is incorrect. O(n^2) suggests quadratic time, which is excessive. O(log n) suggests logarithmic time, which is not applicable.Final Answer:
Option D -> Option DQuick Check:
Dropout involves element-wise operations. [OK]
Hint: Dropout involves element-wise operations. [OK]
Common Mistakes:
4. What is the time complexity of calculating the mean Average Precision (mAP) for a single image with N predicted bounding boxes and M ground truth boxes?
easy
Solution
Step 1: Understand the Process
For each predicted box, IoU is calculated with each ground truth box, leading to N * M comparisons.Step 2: Determine Complexity
Each comparison is constant time, so the overall complexity is O(N * M).Final Answer:
Option C -> Option CQuick Check:
IoU comparisons drive complexity [OK]
Hint: IoU comparisons drive complexity [OK]
Common Mistakes:
5. In the context of mAP calculation, how would you handle a scenario where some classes have very few instances?
medium
Solution
Step 1: Identify the Problem
Classes with few instances can disproportionately affect mAP if not handled properly.Step 2: Evaluate Solutions
Ignore these classes to avoid skewing results: Ignoring classes can lead to incomplete evaluation. Use a weighted mAP where each class contributes equally: Weighted mAP ensures each class contributes equally, addressing imbalance. Increase the IoU threshold for these classes: Increasing IoU threshold doesn't solve the imbalance. Use a different metric like F1-score for these classes: F1-score doesn't address the mAP calculation issue.Final Answer:
Option D -> Option DQuick Check:
Use weighted mAP for class imbalance [OK]
Hint: Use weighted mAP for class imbalance [OK]
Common Mistakes:
