Practice
1. What does the following Python code snippet output when implementing the forward pass of batch normalization?
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
mean = np.mean(X, axis=0)
var = np.var(X, axis=0)
X_norm = (X - mean) / np.sqrt(var + 1e-8)
print(X_norm)easy
Solution
Step 1: Understand the code
The code calculates the mean and variance for each feature, normalizes the data, and prints it.Step 2: Check the normalization
Batch normalization ensures each feature has zero mean and unit variance.Final Answer:
Option C -> Option CQuick Check:
Batch norm: zero mean, unit variance [OK]
Hint: Batch norm: zero mean, unit variance [OK]
Common Mistakes:
2. 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:
3. In which scenario is gradient checking most useful?
medium
Solution
Step 1: Identify scenarios where gradient checking is applicable
Gradient checking is crucial when implementing new components to ensure correctness.Step 2: Eliminate unrelated scenarios
Options A, C, and D are not directly related to verifying gradient correctness.Final Answer:
Option A -> Option AQuick Check:
Use gradient check for new components. [OK]
Hint: Use gradient check for new components. [OK]
Common Mistakes:
4. You implemented linear regression using gradient descent, but the model is not converging. What is the most likely cause?
medium
Solution
Step 1: Identify symptoms of non-convergence
Non-convergence often results from oscillations due to a high learning rate.Step 2: Eliminate other options
Low learning rate causes slow convergence, not non-convergence. Dataset size and feature count affect overfitting, not convergence.Final Answer:
Option B -> Option BQuick Check:
High learning rate causes oscillations. [OK]
Hint: High learning rate causes oscillations. [OK]
Common Mistakes:
5. In a Random Forest implementation, how would you apply feature sampling to handle high-dimensional data effectively?
medium
Solution
Step 1: Understand Feature Sampling
Feature sampling involves selecting a random subset of features for each tree to reduce dimensionality.Step 2: Evaluate Options
Using all features (A) or a fixed subset (C) doesn't reduce dimensionality; correlation-based selection (D) isn't random.Final Answer:
Option C -> Option CQuick Check:
Random subsets reduce dimensionality [OK]
Hint: Random subsets reduce dimensionality [OK]
Common Mistakes:
