Practice
1.
import numpy as np
data = np.array([1, 2, 3, 4, 5])
mean = np.mean(data)
std = np.std(data)
standardized_data = (data - mean) / std
print(standardized_data)What does the code output?easy
Solution
Step 1: Understand Standardization
Standardization transforms data to have a mean of 0 and a standard deviation of 1.Step 2: Calculate the Output
The standardized values are calculated as (data - mean) / std, resulting in [-1.41, -0.71, 0, 0.71, 1.41].Final Answer:
Option C -> Option CQuick Check:
Standardization centers data around 0. [OK]
Hint: Standardization centers data around 0. [OK]
Common Mistakes:
2. 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:
3. A Gaussian Naive Bayes model is giving poor performance on a dataset. Which of the following is the most likely cause?
medium
Solution
Step 1: Identify Gaussian Naive Bayes assumptions
Gaussian Naive Bayes assumes that features are normally distributed.Step 2: Evaluate each option
The features are not normally distributed. is correct because non-normal distribution violates the model's assumptions. The model has too many parameters. is incorrect as GaussianNB is simple. The dataset is too small. is less likely as small datasets affect all models. The features are highly correlated. is incorrect as GaussianNB can handle correlated features.Final Answer:
Option B -> Option BQuick Check:
GaussianNB assumes normal distribution. [OK]
Hint: GaussianNB assumes normal distribution. [OK]
Common Mistakes:
4. 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:
5. How can you optimize the memory usage of the Adam optimizer in a large-scale deep learning model?
hard
Solution
Step 1: Identify memory-intensive components
Adam requires storing additional momentum and velocity arrays, which can be memory-intensive.Step 2: Optimize storage precision
Using half-precision floating points reduces memory usage significantly while maintaining sufficient precision for most deep learning tasks.Final Answer:
Option B -> Option BQuick Check:
Use half-precision to save memory in Adam [OK]
Hint: Use half-precision to save memory in Adam [OK]
Common Mistakes:
