Practice
1.
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:
2. What is the time complexity of cropping an image of size
n x n to a smaller size m x m using NumPy slicing?easy
Solution
Step 1: Understand NumPy slicing
NumPy slicing creates a view, not a copy, so it operates in constant time.Step 2: Evaluate the complexity
The operation does not depend on the size of the arrays but on the slicing indices.Final Answer:
Option B -> Option BQuick Check:
NumPy slicing is O(1) due to views. [OK]
Hint: NumPy slicing is O(1) due to views. [OK]
Common Mistakes:
3. What is the time complexity of computing the forward pass for a single layer in a neural network using NumPy?
easy
Solution
Step 1: Identify operations
Forward pass involves matrix-vector multiplication.Step 2: Determine complexity
Matrix-vector multiplication is O(n) where n is the number of neurons.Final Answer:
Option B -> Option BQuick Check:
Matrix-vector multiplication is O(n) [OK]
Hint: Matrix-vector multiplication is O(n) [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. What is the time complexity of computing the scaled dot-product attention for a single query with n keys?
easy
Solution
Step 1: Identify operations
For a single query, the main operations are dot product and softmax, both O(n).Step 2: Eliminate incorrect complexities
O(n^2) and O(n log n) are incorrect as they imply more complex operations than present.Final Answer:
Option C -> Option CQuick Check:
Single query, n keys -> O(n) [OK]
Hint: Single query, n keys -> O(n) [OK]
Common Mistakes:
