Practice
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 overfitting causes.
Data leakage during feature selection can lead to overfitting as the model sees information from the validation set.Step 2: Eliminate wrong options.
Too few features usually lead to underfitting. An inappropriate scoring function affects feature ranking, not directly overfitting. High variance can cause overfitting but is not specific to wrapper methods.Final Answer:
Option A -> Option AQuick Check:
Data leakage = overfitting risk. [OK]
Solution
Step 1: Identify the need for streaming data handling.
Streaming data requires a strategy that can update samples dynamically.Step 2: Eliminate non-streaming strategies.
Random (A) and Stratified (B) don't handle streaming efficiently. Weighted (D) is for prioritization, not streaming.Final Answer:
Option B -> Option BQuick Check:
Reservoir = Streaming data handling [[check]]
Solution
Step 1: Understand the need for balance.
Fraud detection requires a balance between catching frauds and minimizing false alarms.Step 2: Choose the metric that balances precision and recall.
F1 Score is the harmonic mean of precision and recall, providing a balance.Final Answer:
Option A -> Option AQuick Check:
F1 Score balances precision and recall. [OK]
Solution
Step 1: Identify the need for capturing interactions.
Recommendation systems benefit from understanding user-item interactions.Step 2: Evaluate feature engineering techniques.
Collaborative filtering (A) is a model, not feature engineering. One-hot encoding (B) doesn't capture interactions. Normalizing (D) doesn't enhance interaction capture. Interaction terms (C) explicitly model user-item interactions, improving the system's ability to recommend.Final Answer:
Option A -> Option AQuick Check:
Interaction terms enhance user-item interaction capture. [OK]
