Practice
1. 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:
2. You implemented early stopping in your training loop, but the model still overfits. What is the most likely reason?
medium
Solution
Step 1: Analyze early stopping behavior
Early stopping relies on validation performance to halt training.Step 2: Identify the root cause of overfitting
If the validation set is too small, it may not accurately reflect generalization, leading to overfitting despite early stopping.Final Answer:
Option A -> Option AQuick Check:
Small validation set can mislead early stopping. [OK]
Hint: Small validation set can mislead early stopping. [OK]
Common Mistakes:
3.
def calculate_f1(confusion_matrix):
tp = confusion_matrix[0, 0]
fp = confusion_matrix[1, 0]
fn = confusion_matrix[0, 1]
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1_score = 2 * (precision * recall) / (precision + recall)
return f1_score
confusion_matrix = np.array([[50, 10], [5, 35]])
print(calculate_f1(confusion_matrix))medium
Solution
Step 1: Calculate precision and recall
Precision = 0.9091, Recall = 0.8333.Step 2: Calculate F1-score
F1 = 2 * (0.9091 * 0.8333) / (0.9091 + 0.8333) = 0.8696.Final Answer:
Option B -> Option BQuick Check:
F1 combines precision and recall. [OK]
Hint: F1 combines precision and recall. [OK]
Common Mistakes:
4. How can you optimize the backward pass of batch normalization to improve computational efficiency?
hard
Solution
Step 1: Identify optimization techniques
Fusing operations can reduce computational overhead.Step 2: Evaluate each option
Fusing batch normalization with linear layers reduces redundant computations.Final Answer:
Option A -> Option AQuick Check:
Fuse layers to optimize batch norm [OK]
Hint: Fuse layers to optimize batch norm [OK]
Common Mistakes:
5. How can you optimize the computation of eigenvectors for a large covariance matrix in PCA?
hard
Solution
Step 1: Identify efficient eigenvector computation methods
The power iteration method is efficient for finding the largest eigenvectors of large matrices.Step 2: Eliminate wrong options
Use the full SVD decomposition. is computationally expensive. Use incremental PCA. is for streaming data, not large matrices. Use the Gram-Schmidt process. is for orthogonalization, not eigenvector computation.Final Answer:
Option B -> Option BQuick Check:
Power iteration for large matrix eigenvectors. [OK]
Hint: Power iteration for large matrix eigenvectors. [OK]
Common Mistakes:
