Practice
1. Given the following Python code snippet, what will be the output if the model is trained with biased data?
from sklearn.metrics import accuracy_score
y_true = [0, 1, 1, 0, 1]
y_pred = [0, 1, 1, 0, 0]
accuracy = accuracy_score(y_true, y_pred)
print(accuracy)easy
Solution
Step 1: Calculate the accuracy.
Accuracy is the ratio of correctly predicted instances to the total instances. Here, 3 out of 5 predictions are correct.Step 2: Compute the accuracy.
Correct predictions: [0, 1, 1] -> 0.6Final Answer:
0.6 -> 0.6Quick Check:
Count correct predictions, divide by total. [OK]
Hint: Count correct predictions, divide by total. [OK]
Common Mistakes:
2. Given the following PyTorch code snippet, what will be the output shape of the model's output after fine-tuning?
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)easy
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]
Hint: Final layer determines output shape. [check]
Common Mistakes:
3. A logistic regression model is giving unexpectedly poor predictions. What is a likely cause?
medium
Solution
Step 1: Identify common issues in logistic regression.
Feature scaling is crucial for convergence in logistic regression, especially with gradient-based optimization.Step 2: Eliminate wrong options.
The model is overfitting due to too many features. is less likely as logistic regression is less prone to overfitting. The model is underfitting because of insufficient data. is incorrect because underfitting is more about model complexity. The learning rate is too high, causing divergence. is incorrect as logistic regression typically uses small learning rates.Final Answer:
Option A -> Option AQuick Check:
Check feature scaling for convergence issues [OK]
Hint: Check feature scaling for convergence issues [OK]
Common Mistakes:
4. You are tasked with designing a monitoring system for an ML model in production. Which approach ensures robust detection of both data drift and performance decay?
hard
Solution
Step 1: Identify comprehensive monitoring strategies
Combining statistical tests with performance metrics covers both drift and decay.Step 2: Eliminate wrong options
Implement a feedback loop using user satisfaction surveys. is subjective and indirect. Rely solely on periodic model retraining. is reactive, not proactive. Monitor only the model's prediction confidence scores. is too narrow in scope.Final Answer:
Option B -> Option BQuick Check:
Combine stats and metrics for full coverage [OK]
Hint: Combine stats and metrics for full coverage [OK]
Common Mistakes:
5. You are tasked with developing a system that can autonomously drive a car in a simulated environment. Which learning approach should you prioritize and why?
hard
Solution
Step 1: Identify the task requirements.
The task requires learning optimal strategies in a dynamic environment.Step 2: Eliminate wrong options.
Supervised learning, because it can learn from labeled driving data. is incorrect because labeled data alone doesn't adapt to new scenarios. Unsupervised learning, because it can discover patterns in driving data. is incorrect because pattern discovery doesn't imply strategy learning. Supervised learning, because it can classify different driving scenarios. is incorrect because classification doesn't optimize actions.Final Answer:
Option C -> Option CQuick Check:
Dynamic strategy learning -> Reinforcement learning [OK]
Hint: Dynamic strategy learning -> Reinforcement learning [OK]
Common Mistakes:
