Practice
1. Given the following Python code using Naive Bayes, what will be the output?
from sklearn.naive_bayes import GaussianNB
import numpy as np
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([1, 0, 1])
model = GaussianNB()
model.fit(X, y)
print(model.predict([[2, 2]]))easy
Solution
Step 1: Understand the Code Execution
The code fits a Gaussian Naive Bayes model and predicts the class for a new sample [2, 2].Step 2: Analyze the Prediction
Given the training data, the model predicts class 1 for [2, 2] based on the likelihoods.Final Answer:
Option A -> Option AQuick Check:
GaussianNB predicts based on likelihoods. [[check]]
Hint: GaussianNB predicts based on likelihoods. [[check]]
Common Mistakes:
2. A model using Batch Normalization is showing unstable training behavior with fluctuating loss. What is the most likely cause?
medium
Solution
Step 1: Identify the role of batch size in Batch Normalization.
Batch Normalization relies on accurate batch statistics, which can be unreliable with small batch sizes.Step 2: Eliminate other causes.
The learning rate is too high, causing instability. is a common issue but not specific to Batch Norm. The model architecture is too deep, causing vanishing gradients. is unrelated to normalization. The dataset is imbalanced, affecting the normalization process. affects model performance but not directly related to Batch Norm instability.Final Answer:
Option A -> Option AQuick Check:
Small batch size causes unstable Batch Norm. [OK]
Hint: Small batch size causes unstable Batch Norm. [OK]
Common Mistakes:
3. A Random Forest model is underperforming on out-of-distribution (OOD) data. What is the most likely cause?
medium
Solution
Step 1: Identify OOD challenges
OOD performance issues often arise from a lack of diversity in training data.Step 2: Analyze options
The training data lacks diversity is correct because diverse training data is crucial for generalization. The model has too many trees is incorrect as more trees generally improve robustness. The model is overfitting to the training data is incorrect because overfitting affects in-distribution performance more. The model uses too few features per split is incorrect as using fewer features can help generalization.Final Answer:
Option B -> Option BQuick Check:
OOD issues often stem from non-diverse data. [OK]
Hint: OOD issues often stem from non-diverse data. [OK]
Common Mistakes:
4. In a real-time prediction system, how should you handle data splits to ensure both model performance and system efficiency?
hard
Solution
Step 1: Consider real-time constraints
Real-time systems need to adapt to new data while maintaining performance.Step 2: Evaluate options for adaptability and efficiency
Use a single train-test split to minimize latency. risks overfitting. Use a large test set to ensure model robustness. misallocates resources. Use a static validation set to simplify the system. lacks adaptability to new data.Final Answer:
Option D -> Option DQuick Check:
Rolling window adapts to new data efficiently. [OK]
Hint: Rolling window adapts to new data efficiently. [OK]
Common Mistakes:
5. You are tasked with adapting a pretrained language model for a sentiment analysis task in a low-resource language. Which approach is most suitable?
hard
Solution
Step 1: Consider the constraints of low-resource languages.
Fine-tuning on a small corpus allows the model to adapt to the specific language nuances.Step 2: Eliminate wrong options.
Translate the low-resource language data to English and fine-tune the English model. might lose language-specific nuances. Use the pretrained model as is, without any fine-tuning. won't adapt the model to the new language. Train a new model from scratch using the low-resource language data. is impractical due to limited data.Final Answer:
Option B -> Option BQuick Check:
Fine-tune on small corpus for low-resource languages. [check]
Hint: Fine-tune on small corpus for low-resource languages. [check]
Common Mistakes:
