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.
import numpy as np
confusion_matrix = np.array([[50, 10], [5, 35]])
precision = confusion_matrix[0, 0] / (confusion_matrix[0, 0] + confusion_matrix[1, 0])
recall = confusion_matrix[0, 0] / (confusion_matrix[0, 0] + confusion_matrix[0, 1])
print(f"Precision: {precision}, Recall: {recall}")easy
Solution
Step 1: Calculate Precision
Precision is calculated as TP / (TP + FP) = 50 / (50 + 5) = 0.9091.Step 2: Calculate Recall
Recall is calculated as TP / (TP + FN) = 50 / (50 + 10) = 0.8333.Final Answer:
Option D -> Option DQuick Check:
Precision uses FP, Recall uses FN. [OK]
Hint: Precision uses FP, Recall uses FN. [OK]
Common Mistakes:
3.
import numpy as np
def euclidean_distance(a, b):
return np.sqrt(np.sum((a - b) ** 2))
vector1 = np.array([1, 2, 3])
vector2 = np.array([4, 5])
result = euclidean_distance(vector1, vector2)
print(result)medium
Solution
Step 1: Check vector shapes
vector1 has shape (3,), vector2 has shape (2,).Step 2: Identify operation failure
Subtraction fails due to shape mismatch, raising a ValueError.Final Answer:
Option B -> Option BQuick Check:
Shape mismatch leads to ValueError. [OK]
Hint: Shape mismatch leads to ValueError. [OK]
Common Mistakes:
4. You implemented PCA but the variance explained by the first principal component is unexpectedly low. What is the most likely cause?
medium
Solution
Step 1: Identify the impact of centering data
Centering data is crucial for PCA as it ensures the covariance matrix reflects true variance.Step 2: Eliminate wrong options
Eigenvectors were not normalized. is incorrect because normalization affects direction, not variance. Covariance matrix was computed using rowvar=True. affects orientation, not variance. Too few principal components were selected. is irrelevant to the variance of the first component.Final Answer:
Option A -> Option AQuick Check:
Center data before PCA to capture variance. [OK]
Hint: Center data before PCA to capture variance. [OK]
Common Mistakes:
5. How can you optimize the dropout layer implementation to reduce computational overhead during training?
hard
Solution
Step 1: Identify Optimization Opportunities
In-place operations reduce memory usage and computational overhead by modifying data directly.Step 2: Eliminate Wrong Options
Use a fixed mask for all training iterations. reduces randomness, harming model performance. Precompute masks for all layers before training. increases memory usage. Reduce the dropout rate to minimize mask application. changes model behavior, not efficiency.Final Answer:
Option A -> Option AQuick Check:
In-place operations save memory and time. [OK]
Hint: In-place operations save memory and time. [OK]
Common Mistakes:
