Practice
Solution
Step 1: Identify the purpose of feature selection.
L1 Lasso regularization can shrink some coefficients to zero, effectively selecting features.Step 2: Eliminate wrong options.
L2 Ridge does not shrink coefficients to zero. Elastic Net combines L1 and L2 but is not as direct for feature selection. Dropout is not used in linear regression.Final Answer:
Option A -> Option AQuick Check:
L1 Lasso zeros coefficients for selection. [OK]
import torch
import torch.nn as nn
class SimpleModel(nn.Module):
def __init__(self):
super(SimpleModel, self).__init__()
self.features = nn.Sequential(
nn.Linear(512, 256),
nn.ReLU(),
nn.Linear(256, 128)
)
self.classifier = nn.Linear(128, 10)
def forward(self, x):
x = self.features(x)
x = self.classifier(x)
return x
model = SimpleModel()
input_data = torch.randn(32, 512)
output = model(input_data)
print(output.shape)Solution
Step 1: Trace the forward pass.
The input shape is (32, 512). After passing through the features, it becomes (32, 128). The classifier then outputs (32, 10).Step 2: Eliminate wrong options.
torch.Size([32, 512]) is incorrect because the output is not the same as the input. torch.Size([32, 256]) and C are intermediate shapes, not the final output.Final Answer:
Option C -> Option CQuick Check:
Final layer determines output shape. [check]
Solution
Step 1: Identify Naive Bayes Limitations
Naive Bayes assumes feature independence given the class label.Step 2: Evaluate Each Option
When the dataset is very large. is incorrect because Naive Bayes handles large datasets well. When you need a probabilistic output. is incorrect because Naive Bayes provides probabilistic outputs. When the dataset has missing values. is incorrect because Naive Bayes can handle missing values with some preprocessing.Final Answer:
Option D -> Option DQuick Check:
Correlated features break Naive Bayes. [[check]]
Solution
Step 1: Consider the nature of time-series data
Time-series data often relies on temporal continuity.Step 2: Evaluate imputation strategies
Forward fill maintains temporal order, while mean and KNN ignore sequence. Backward fill is less intuitive for future predictions.Final Answer:
Option C -> Option CQuick Check:
Forward fill for time-series [OK]
Solution
Step 1: Consider real-time constraints
Stochastic Gradient Descent (SGD) updates weights after each data point, allowing for faster, more frequent updates suitable for real-time systems.Step 2: Eliminate wrong options
Batch Gradient Descent (A) is too slow for real-time, Least Squares (C) is not iterative, and Mini-batch (D) is a compromise but not as fast as SGD.Final Answer:
Option A -> Option AQuick Check:
SGD updates weights after each data point. [OK]
