Practice
1. What is the time complexity of fitting a Multinomial Naive Bayes model on a dataset with n samples and m features?
easy
Solution
Step 1: Analyze the fitting process
Fitting a Multinomial Naive Bayes involves calculating probabilities for each feature across all samples.Step 2: Determine complexity
This requires iterating over each feature for each sample, leading to O(n * m) complexity.Final Answer:
Option D -> Option DQuick Check:
Multinomial NB fitting is O(n * m). [OK]
Hint: Multinomial NB fitting is O(n * m). [OK]
Common Mistakes:
2. What is the time complexity of computing the scaled dot-product attention for a single query with n keys?
easy
Solution
Step 1: Identify operations
For a single query, the main operations are dot product and softmax, both O(n).Step 2: Eliminate incorrect complexities
O(n^2) and O(n log n) are incorrect as they imply more complex operations than present.Final Answer:
Option C -> Option CQuick Check:
Single query, n keys -> O(n) [OK]
Hint: Single query, n keys -> O(n) [OK]
Common Mistakes:
3. 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:
4. In a multi-class classification problem, how should precision and recall be calculated from a confusion matrix?
medium
Solution
Step 1: Understand multi-class metrics
Precision and recall should be calculated for each class separately.Step 2: Determine the correct aggregation method
Average the precision and recall across all classes to get a balanced view.Final Answer:
Option A -> Option AQuick Check:
Average class-wise metrics for multi-class. [OK]
Hint: Average class-wise metrics for multi-class. [OK]
Common Mistakes:
5. How can you optimize the K-Means implementation to improve its performance on large datasets?
hard
Solution
Step 1: Identify performance bottlenecks
The Elkan algorithm optimizes K-Means by reducing the number of distance calculations needed.Step 2: Eliminate wrong options
Increase the number of iterations. increases computation. Decrease the number of clusters. may not be suitable for the data's natural structure. Use a smaller subset of data for training. reduces accuracy.Final Answer:
Option A -> Option AQuick Check:
Elkan reduces distance calculations. [OK]
Hint: Elkan reduces distance calculations. [OK]
Common Mistakes:
