Practice
1.
from sklearn.model_selection import KFold
import numpy as np
X = np.array([1, 2, 3, 4, 5])
kf = KFold(n_splits=2)
for train_index, test_index in kf.split(X):
print("Train:", train_index, "Test:", test_index)
What will be the output of the above code?easy
Solution
Step 1: Understand KFold behavior
KFold splits the data into n_splits parts, here 2, and iterates over them.Step 2: Eliminate wrong options
Train: [0 1 2 3] Test: [4] and Train: [4] Test: [0 1 2 3] and D suggest incorrect split sizes. Train: [0 1] Test: [2 3 4] and Train: [2 3 4] Test: [0 1] suggests incorrect indexing.Final Answer:
Option B -> Option BQuick Check:
KFold splits into equal parts. [OK]
Hint: KFold splits data into equal parts. [OK]
Common Mistakes:
2. What is the time complexity of a single update step in Mini-Batch SGD with Momentum for a model with
n parameters?easy
Solution
Step 1: Identify operations involved
Each update step involves computing the gradient and updating the velocity and parameters, all of which are linear operations with respect to the number of parameters.Step 2: Determine the complexity
Since each operation is linear, the overall complexity isO(n).Final Answer:
Option A -> Option AQuick Check:
Each parameter update is linear in complexity [OK]
Hint: Each parameter update is linear in complexity [OK]
Common Mistakes:
3. In a recommendation system, why might you choose cosine similarity over Euclidean distance?
medium
Solution
Step 1: Compare properties
Cosine similarity measures angle, not magnitude, making it invariant to vector length.Step 2: Eliminate incorrect reasons
Cosine similarity isn't inherently faster (A), doesn't handle missing data better (C), and interpretability is subjective (D).Final Answer:
Option A -> Option AQuick Check:
Cosine ignores magnitude, focuses on direction. [OK]
Hint: Cosine ignores magnitude, focuses on direction. [OK]
Common Mistakes:
4.
import numpy as np
def ndcg_at_k(r, k):
dcg_max = dcg_at_k(sorted(r, reverse=True), k)
if not dcg_max:
return 0.
return dcg_at_k(r, k) / dcg_max
relevance_scores = [3, 2, 3, 0, 1, 2]
k = 3
print(ndcg_at_k(relevance_scores, k))The output is unexpectedly low. What is the most likely cause?medium
Solution
Step 1: Check Ideal DCG Calculation
The ideal DCG should be calculated using the sorted relevance scores.Step 2: Identify the Error
If the ideal DCG is not calculated correctly, the NDCG will be incorrect.Final Answer:
Option D -> Option DQuick Check:
Check ideal DCG calculation. [OK]
Hint: Check ideal DCG calculation. [OK]
Common Mistakes:
5. How can you optimize the numerical gradient computation for a large neural network?
hard
Solution
Step 1: Identify optimization strategies for numerical gradient computation
Parallelizing the computation can significantly reduce time for large networks.Step 2: Eliminate ineffective strategies
Options A, C, and D do not directly optimize the gradient computation process.Final Answer:
Option B -> Option BQuick Check:
Parallelize for large networks. [OK]
Hint: Parallelize for large networks. [OK]
Common Mistakes:
