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. A model trained with Adam optimizer is not converging. What is the most likely cause?
medium
Solution
Step 1: Identify common issues with Adam.
Adam can be sensitive to high learning rates, causing divergence.Step 2: Eliminate less likely causes.
Adam handles non-convex problems well, and batch size/weight decay are less likely to cause non-convergence.Final Answer:
Option B -> Option BQuick Check:
High lr can cause Adam to diverge. [check]
Hint: High lr can cause Adam to diverge. [check]
Common Mistakes:
3. You implemented stratified sampling but notice that the sample still has class imbalance. What is the most likely cause?
medium
Solution
Step 1: Identify the stratified sampling requirement.
Stratified sampling requires correct class proportion specification.Step 2: Eliminate unrelated issues.
Random Sampling (B) would not be used if stratified was intended. Data leakage (C) affects model performance, not sampling. Sample size (D) affects variability, not imbalance directly.Final Answer:
Option C -> Option CQuick Check:
Check class proportions in stratified sampling [[check]]
Hint: Check class proportions in stratified sampling [[check]]
Common Mistakes:
4. You are tasked with implementing a real-time prediction system using LightGBM. Which approach ensures the lowest latency?
hard
Solution
Step 1: Identify latency reduction strategies
Reducing the number of trees and their depth directly decreases computation time per prediction.Step 2: Eliminate wrong options
Use a batch prediction approach to handle multiple requests at once. is incorrect because batch processing increases latency for individual requests. Deploy the model on a high-performance GPU server. is incorrect because LightGBM is CPU-optimized. Use a distributed computing framework to parallelize predictions. is incorrect because distributed frameworks add overhead, increasing latency.Final Answer:
Option C -> Option CQuick Check:
Fewer trees = Lower latency [OK]
Hint: Fewer trees = Lower latency [OK]
Common Mistakes:
5. You are tasked with improving a model's performance on a highly imbalanced dataset. Which approach is most appropriate to prevent overfitting while addressing class imbalance?
hard
Solution
Step 1: Address class imbalance and overfitting
Class weights help balance the dataset, and early stopping prevents overfitting by halting training when validation performance stops improving.Step 2: Eliminate wrong options
Use SMOTE to oversample the minority class and increase model complexity. increases complexity, risking overfitting, Downsample the majority class and increase the learning rate. may lead to instability, and Use a simpler model with no regularization. lacks regularization, increasing overfitting risk.Final Answer:
Option C -> Option CQuick Check:
Class weights + early stopping = balanced, robust model [OK]
Hint: Class weights + early stopping = balanced, robust model [OK]
Common Mistakes:
