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 calculating precision, recall, and F1-score from a confusion matrix?
easy
Solution
Step 1: Analyze the operations
Calculating precision, recall, and F1-score involves basic arithmetic operations on a fixed-size matrix.Step 2: Determine complexity
These operations are constant time, O(1), as they do not depend on the size of the input data.Final Answer:
Option A -> Option AQuick Check:
Fixed-size matrix operations are O(1). [OK]
Hint: Fixed-size matrix operations are O(1). [OK]
Common Mistakes:
3. What is the time complexity of computing the softmax function for an input array of size n?
easy
Solution
Step 1: Analyze operations
Softmax involves computing exponentials and a sum, both linear in n.Step 2: Determine complexity
Each operation is O(n), so overall complexity is O(n).Final Answer:
Option D -> Option DQuick Check:
Softmax is linear in input size [OK]
Hint: Softmax is linear in input size [OK]
Common Mistakes:
4.
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([1, 2, 3, 4, 5, 6])
y = np.array([0, 0, 1, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, stratify=y)
print(y_train)easy
Solution
Step 1: Understand stratification
Stratification ensures that the class distribution in the train and test sets is similar to the original dataset.Step 2: Calculate class distribution
Original y has 3 zeros and 3 ones. With stratification, y_train should have 1 zero and 2 ones.Final Answer:
Option D -> Option DQuick Check:
Stratify maintains class distribution. [OK]
Hint: Stratify maintains class distribution. [OK]
Common Mistakes:
5. How can you optimize the backward pass of batch normalization to improve computational efficiency?
hard
Solution
Step 1: Identify optimization techniques
Fusing operations can reduce computational overhead.Step 2: Evaluate each option
Fusing batch normalization with linear layers reduces redundant computations.Final Answer:
Option A -> Option AQuick Check:
Fuse layers to optimize batch norm [OK]
Hint: Fuse layers to optimize batch norm [OK]
Common Mistakes:
