Practice
1. What is the time complexity of computing a confusion matrix for a binary classification problem with n predictions?
easy
Solution
Step 1: Analyze the operation
Computing a confusion matrix involves iterating over predictions once.Step 2: Determine complexity
Each prediction is checked once, leading to O(n) complexity.Final Answer:
Option C -> Option CQuick Check:
Confusion matrix computation is linear in predictions. [OK]
Hint: Confusion matrix computation is linear in predictions. [OK]
Common Mistakes:
2. What is the time complexity of computing the numerical gradient for a function with n parameters using central difference?
easy
Solution
Step 1: Analyze the loop structure
The numerical gradient computation involves a loop over n parameters, each requiring constant time operations.Step 2: Determine the complexity
Each parameter requires a constant number of operations, leading to O(n) complexity.Final Answer:
Option D -> Option DQuick Check:
Loop over n parameters, each constant time. [OK]
Hint: Loop over n parameters, each constant time. [OK]
Common Mistakes:
3.
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:
4. What does the following Python code snippet output when implementing a simple bagging technique for a Random Forest?
import numpy as np
from sklearn.utils import resample
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
# Bagging
bagged_X = resample(X, n_samples=3, replace=True, random_state=42)
print(bagged_X)easy
Solution
Step 1: Understand Bagging with Replacement
Bagging involves sampling with replacement, meaning samples can be repeated.Step 2: Analyze Code Output
The code usesresamplewithreplace=True, so duplicates are possible.Final Answer:
Option A -> Option AQuick Check:
Bagging allows duplicates [OK]
Hint: Bagging allows duplicates [OK]
Common Mistakes:
5. 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:
