Practice
1.
import numpy as np
# Forward pass for a single neuron
inputs = np.array([1.0, 2.0, 3.0])
weights = np.array([0.2, 0.8, -0.5])
bias = 2.0
output = np.dot(inputs, weights) + bias
print(output)easy
Solution
Step 1: Calculate dot product
np.dot(inputs, weights) = 1.0*0.2 + 2.0*0.8 + 3.0*(-0.5) = 0.2 + 1.6 - 1.5 = 0.3Step 2: Add bias
0.3 + 2.0 = 2.3Final Answer:
Option A -> Option AQuick Check:
Dot product then add bias [OK]
Hint: Dot product then add bias [OK]
Common Mistakes:
2. What is the time complexity of the following non-max suppression implementation?
def non_max_suppression(boxes, scores, iou_threshold):
indices = np.argsort(scores)[::-1]
keep = []
while len(indices) > 0:
current = indices[0]
keep.append(current)
indices = indices[1:]
indices = [i for i in indices if iou(boxes[current], boxes[i]) < iou_threshold]
return keepeasy
Solution
Step 1: Analyze the loop structure
The outer loop runs n times, and the inner loop (IoU calculation) also runs n times in the worst case.Step 2: Determine complexity
Each IoU calculation is O(1), making the overall complexity O(n^2).Final Answer:
Option B -> Option BQuick Check:
Nested loops suggest O(n^2) [OK]
Hint: Nested loops suggest O(n^2) [OK]
Common Mistakes:
3. What is the time complexity of training a Random Forest with bagging and feature sampling, assuming each tree is trained on a subset of m features from n samples?
easy
Solution
Step 1: Analyze Tree Training Complexity
Each decision tree in a Random Forest is trained on a subset of features and samples.Step 2: Determine Complexity
Training a decision tree typically involves sorting, leading to O(n * m * log(n)) complexity.Final Answer:
Option D -> Option DQuick Check:
Tree training involves sorting [OK]
Hint: Tree training involves sorting [OK]
Common Mistakes:
4. In a multi-class classification problem, how should you modify the confusion matrix implementation to handle more than two classes?
medium
Solution
Step 1: Understand multi-class needs
Each class needs its own row and column in the matrix.Step 2: Choose correct matrix size
A (n_classes, n_classes) matrix captures all class interactions.Final Answer:
Option D -> Option DQuick Check:
Multi-class needs (n_classes, n_classes) matrix. [OK]
Hint: Multi-class needs (n_classes, n_classes) matrix. [OK]
Common Mistakes:
5. How can you optimize the memory usage of a NumPy-based backpropagation implementation for a large neural network?
hard
Solution
Step 1: Identify memory bottlenecks
Intermediate results can consume significant memory.Step 2: Optimize memory usage
In-place operations reduce memory overhead by modifying data directly.Final Answer:
Option A -> Option AQuick Check:
In-place operations save memory [OK]
Hint: In-place operations save memory [OK]
Common Mistakes:
