Practice
1. What does the following Python code output when applied to an image array
img?
import numpy as np
def flip_image(img):
return np.flip(img, axis=1)
img = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
flipped_img = flip_image(img)
print(flipped_img)easy
Solution
Step 1: Understand the flip operation
Thenp.flipfunction flips the array along the specified axis. Here, axis=1 means flipping horizontally.Step 2: Apply the flip to the array
Flipping horizontally changes the order of elements in each row.Final Answer:
Option A -> Option AQuick Check:
Horizontal flip reverses row elements. [OK]
Hint: Horizontal flip reverses row elements. [OK]
Common Mistakes:
2. 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:
3. What does the following Python code snippet output when implementing sinusoidal positional encoding?
import numpy as np
def positional_encoding(position, d_model):
angle_rads = np.arange(position)[:, np.newaxis] / np.power(10000, (2 * (np.arange(d_model)[np.newaxis, :] // 2)) / np.float32(d_model))
angle_rads[:, 0::2] = np.sin(angle_rads[:, 0::2])
angle_rads[:, 1::2] = np.cos(angle_rads[:, 1::2])
return angle_rads
pe = positional_encoding(4, 4)
print(pe)easy
Solution
Step 1: Understand the code logic
The code generates a matrix where each row corresponds to a position and each column to a dimension, filled with sinusoidal values.Step 2: Eliminate wrong options
A 4x4 matrix with all zeros is incorrect because the matrix is not filled with zeros. A 4x4 identity matrix is incorrect because the matrix is not an identity matrix. A 4x4 matrix with random values is incorrect because the values are not random but deterministic sinusoidal values.Final Answer:
Option A -> Option AQuick Check:
Sinusoidal encoding alternates sine/cosine. [OK]
Hint: Sinusoidal encoding alternates sine/cosine. [OK]
Common Mistakes:
4. What does the following Python code output when computing the ROC curve?
from sklearn.metrics import roc_curve
import numpy as np
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
print(fpr, tpr, thresholds)easy
Solution
Step 1: Understand ROC curve output
The ROC curve function returns false positive rates (fpr), true positive rates (tpr), and thresholds.Step 2: Analyze the code
Given the scores and true labels, the ROC curve is calculated correctly, resulting in fpr, tpr, and thresholds as in array([0. , 0.5, 1. ]), array([0. , 0.5, 1. ]), array([0.8, 0.35, 0.1]).Final Answer:
Option C -> Option CQuick Check:
ROC curve outputs fpr, tpr, thresholds [OK]
Hint: ROC curve outputs fpr, tpr, thresholds [OK]
Common Mistakes:
5. 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:
