Practice
1. What is the time complexity of computing the binary cross-entropy loss for a logistic regression model with
n samples and m features?easy
Solution
Step 1: Identify operations involved
Binary cross-entropy involves computing predictions for each sample, which requires a dot product of weights and features.Step 2: Calculate complexity
Each dot product is O(m), and there are n samples, leading to O(nm) complexity.Final Answer:
Option D -> Option DQuick Check:
Dot product per sample, n samples -> O(nm) [OK]
Hint: Dot product per sample, n samples -> O(nm) [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. How can you optimize a KD-Tree implementation for a KNN classifier to handle large datasets more efficiently?
hard
Solution
Step 1: Identify optimization strategies
Approximate nearest neighbors can significantly speed up queries in large datasets.Step 2: Evaluate other options
A: Balancing helps but isn't enough for large datasets. B: Increasing dimensions worsens performance. D: Reducing data points isn't always feasible.Final Answer:
Option B -> Option BQuick Check:
Approximate neighbors speed up KD-Tree [OK]
Hint: Approximate neighbors speed up KD-Tree [OK]
Common Mistakes:
4. How can you optimize the computation of the ROC curve for a large dataset?
hard
Solution
Step 1: Identify optimization strategies
Parallel processing can speed up computation by handling different thresholds simultaneously.Step 2: Eliminate wrong options
Use a smaller batch size for computation. doesn't address the core computation, Use a subset of data to approximate the ROC curve. may reduce accuracy, Use a more efficient sorting algorithm for the scores. is limited by sorting algorithm constraints.Final Answer:
Option D -> Option DQuick Check:
Parallel processing speeds up ROC computation [OK]
Hint: Parallel processing speeds up ROC computation [OK]
Common Mistakes:
5. How can you optimize the computation of softmax and cross-entropy loss for a batch of inputs in a neural network?
hard
Solution
Step 1: Identify optimization opportunity
Combining softmax and cross-entropy avoids intermediate storage of probabilities.Step 2: Reduce computational overhead
This reduces both memory usage and computational cost.Final Answer:
Option C -> Option CQuick Check:
Combine operations to save resources [OK]
Hint: Combine operations to save resources [OK]
Common Mistakes:
