Practice
1. What is the time complexity of finding the nearest neighbors using a brute force approach in a KNN classifier?
easy
Solution
Step 1: Understand brute force KNN
Brute force KNN involves calculating the distance from the query point to all training points.Step 2: Analyze complexity
For each of the n training points, we compute the distance in d dimensions, leading to O(n * d).Final Answer:
Option C -> Option CQuick Check:
Brute force KNN: O(n * d) [OK]
Hint: Brute force KNN: O(n * d) [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. What is the time complexity of updating the embeddings for a single word pair in the Skip-Gram model with negative sampling?
easy
Solution
Step 1: Identify the operations involved
Updating embeddings involves computing gradients and updating weights for the target word and k negative samples.Step 2: Determine the complexity
Each update involves a constant number of operations per sample, leading to O(k) complexity where k is the number of negative samples.Final Answer:
Option A -> Option AQuick Check:
Complexity is O(k) due to k negative samples [OK]
Hint: Complexity is O(k) due to k negative samples [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 memory usage of a Random Forest implementation with bagging and feature sampling?
hard
Solution
Step 1: Identify Memory Optimization Techniques
Using smaller data types can significantly reduce memory usage.Step 2: Evaluate Options
Using a single tree (A) reduces model complexity, not memory; reducing features (B) affects accuracy; serialization (D) affects storage, not runtime memory.Final Answer:
Option B -> Option BQuick Check:
Smaller data types save memory [OK]
Hint: Smaller data types save memory [OK]
Common Mistakes:
