Practice
1. What is the time complexity of applying Min-Max scaling to a dataset with n samples and m features?
easy
Solution
Step 1: Understand Min-Max Scaling
Min-Max scaling requires computing the min and max for each feature, which involves iterating over all samples for each feature.Step 2: Calculate Complexity
For each of the m features, we iterate over n samples, resulting in O(n * m) complexity.Final Answer:
Option A -> Option AQuick Check:
Min-Max scaling is O(n * m). [OK]
Hint: Min-Max scaling is O(n * m). [OK]
Common Mistakes:
2.
import numpy as np
def numerical_gradient(f, x):
h = 1e-4
grad = np.zeros_like(x)
for i in range(x.size):
x[i] += h
fxh1 = f(x)
x[i] -= 2 * h
fxh2 = f(x)
grad[i] = (fxh1 - fxh2) / (2 * h)
x[i] += h
return grad
# Test function
f = lambda x: x[0]**2 + x[1]**2
x = np.array([3.0, 4.0])
print(numerical_gradient(f, x))easy
Solution
Step 1: Understand the numerical gradient calculation
The function calculates the gradient using central difference approximation.Step 2: Calculate the gradient for each element
For x = [3.0, 4.0], the gradient is [6.0, 8.0] because the derivative of x^2 is 2x.Final Answer:
Option A -> Option AQuick Check:
Central difference gives exact gradient for quadratic. [OK]
Hint: Central difference gives exact gradient for quadratic. [OK]
Common Mistakes:
3. In a pipeline that includes flipping, cropping, and normalizing images, where should normalization be applied for best results?
medium
Solution
Step 1: Understand the impact of operations
Normalization should be the last step to ensure consistent scaling.Step 2: Evaluate each option
Applying normalization last ensures it accounts for all transformations.Final Answer:
Option D -> Option DQuick Check:
Normalize last for consistent scaling. [OK]
Hint: Normalize last for consistent scaling. [OK]
Common Mistakes:
4. In the implementation of Adam optimizer, the model is not converging. Which line of code is most likely causing the issue?
medium
Solution
Step 1: Identify the potential issue
The lineparameter -= learning_rate * m_hat / (np.sqrt(v_hat) + epsilon)is crucial for parameter updates. Ifepsilonis not properly set, it can cause division by zero or very small updates.Step 2: Eliminate other options
Options A, B, and C are standard parts of the Adam algorithm and unlikely to cause convergence issues unless there's a typo or logical error.Final Answer:
Option A -> Option AQuick Check:
Check epsilon in Adam's update step [OK]
Hint: Check epsilon in Adam's update step [OK]
Common Mistakes:
5. How can you optimize the following data augmentation pipeline for memory efficiency?
def augment_image(img):
img = np.flip(img, axis=1)
img = img[10:110, 10:110]
img = (img - np.mean(img)) / np.std(img)
return imghard
Solution
Step 1: Identify memory inefficiencies
Intermediate assignments create unnecessary copies.Step 2: Evaluate optimization strategies
Chaining operations reduces memory usage by avoiding intermediate arrays.Final Answer:
Option A -> Option AQuick Check:
Chain operations to reduce memory usage. [OK]
Hint: Chain operations to reduce memory usage. [OK]
Common Mistakes:
