Practice
1. What does the following Python code snippet output when implementing linear regression using gradient descent?
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array([1, 2, 3])
weights = np.zeros(X.shape[1])
learning_rate = 0.01
for _ in range(1):
predictions = X.dot(weights)
errors = predictions - y
gradient = X.T.dot(errors) / len(y)
weights -= learning_rate * gradient
print(weights)easy
Solution
Step 1: Calculate initial predictions and errors
Initial predictions are [0, 0, 0] since weights are zeros. Errors are [-1, -2, -3].Step 2: Compute gradient and update weights
Gradient is [-3, -6]. Updated weights are [0.01, 0.02].Final Answer:
Option A -> Option AQuick Check:
Initial weights zero, single update step. [OK]
Hint: Initial weights zero, single update step. [OK]
Common Mistakes:
2. What does the following Python code snippet output when implementing Mini-Batch SGD with Momentum?
import numpy as np
velocity = np.array([0.0, 0.0])
gradient = np.array([0.1, 0.2])
learning_rate = 0.01
momentum = 0.9
velocity = momentum * velocity - learning_rate * gradient
print(velocity)easy
Solution
Step 1: Calculate the velocity update
The formula for velocity update isvelocity = momentum * velocity - learning_rate * gradient. Given the initial velocity is zero, the update becomesvelocity = -learning_rate * gradient.Step 2: Substitute the values
Substitutelearning_rate = 0.01andgradient = [0.1, 0.2]into the formula:velocity = -0.01 * [0.1, 0.2] = [-0.001, -0.002].Final Answer:
Option C -> Option CQuick Check:
Velocity update is negative of learning rate times gradient [OK]
Hint: Velocity update is negative of learning rate times gradient [OK]
Common Mistakes:
3. What is the time complexity of performing a train-test split with stratification on a dataset with n samples?
easy
Solution
Step 1: Analyze the operation
Train-test split with stratification involves iterating over the dataset once to ensure class distribution.Step 2: Determine complexity
Since each element is processed once, the complexity is O(n).Final Answer:
Option A -> Option AQuick Check:
Stratified split processes each sample once. [OK]
Hint: Stratified split processes each sample once. [OK]
Common Mistakes:
4. Your mAP implementation is returning unusually high values. What is the most likely cause?
medium
Solution
Step 1: Identify the Symptom
High mAP values suggest too many matches are considered correct.Step 2: Analyze Each Option
Incorrect IoU threshold for positive matches: A low IoU threshold can cause false positives to be counted as true positives, inflating mAP. Using precision instead of recall in calculations: Would affect recall, not mAP directly. Not normalizing the precision values: Would affect the scale, not the value. Including false negatives in the precision calculation: Would lower precision, not increase it.Final Answer:
Option B -> Option BQuick Check:
Check IoU threshold for false positives [OK]
Hint: Check IoU threshold for false positives [OK]
Common Mistakes:
5. How can you optimize the memory usage of the Adam optimizer in a large-scale deep learning model?
hard
Solution
Step 1: Identify memory-intensive components
Adam requires storing additional momentum and velocity arrays, which can be memory-intensive.Step 2: Optimize storage precision
Using half-precision floating points reduces memory usage significantly while maintaining sufficient precision for most deep learning tasks.Final Answer:
Option B -> Option BQuick Check:
Use half-precision to save memory in Adam [OK]
Hint: Use half-precision to save memory in Adam [OK]
Common Mistakes:
