Practice
1. Given the following Python code snippet, what will be the output if the dataset contains data leakage?
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(accuracy_score(y_test, y_pred))easy
Solution
Step 1: Understand the impact of data leakage
Data leakage often results in overly optimistic performance metrics.Step 2: Analyze the code behavior
The code will execute without errors, but if leakage exists, the model will perform better than it should.Final Answer:
Option D -> Option DQuick Check:
Leakage inflates accuracy [OK]
Hint: Leakage inflates accuracy [OK]
Common Mistakes:
2. When debugging a model with high variance, which approach is more suitable?
medium
Solution
Step 1: Identify high variance symptoms
High variance indicates overfitting, where the model performs well on training data but poorly on unseen data.Step 2: Choose the right approach
Adding more training data helps the model generalize better, reducing overfitting.Final Answer:
Option B -> Option BQuick Check:
High variance = more data [OK]
Hint: High variance = more data [OK]
Common Mistakes:
3. When deciding between offline and online evaluation for a new feature in a web application, which approach is more suitable if user feedback is critical and why?
medium
Solution
Step 1: Identify the need for user feedback.
When user feedback is critical, capturing real interactions is essential.Step 2: Evaluate the suitability of each approach.
Offline evaluation, because it allows for controlled experiments. is incorrect because controlled experiments do not capture real-time feedback. Offline evaluation, because it is faster and less resource-intensive. is incorrect because speed and resource usage do not address feedback needs. Online evaluation, because it avoids overfitting to historical data. is partially correct but does not emphasize feedback.Final Answer:
Option B -> Option BQuick Check:
Real feedback needs online evaluation. [OK]
Hint: Real feedback needs online evaluation. [OK]
Common Mistakes:
4. When considering bias mitigation strategies, which approach is more suitable for a scenario where you cannot alter the training data but need to ensure fairness in predictions?
medium
Solution
Step 1: Identify the constraint.
Cannot alter training data, need fairness in predictions.Step 2: Choose the suitable technique.
Post-processing techniques adjust predictions to ensure fairness without altering the model or data.Final Answer:
Option D -> Option DQuick Check:
Post-processing adjusts predictions, not data. [OK]
Hint: Post-processing adjusts predictions, not data. [OK]
Common Mistakes:
5. When dealing with high-dimensional data, which approach is more suitable for reducing dimensionality while preserving variance?
medium
Solution
Step 1: Identify the goal of preserving variance.
PCA is designed to reduce dimensions while preserving variance.Step 2: Eliminate wrong options.
Use L1 regularization to select features. selects features, not reduce dimensions. Use k-means clustering to group similar data points. clusters data, not reduce dimensions. Apply dropout to randomly ignore features during training. is for regularization, not dimensionality reduction.Final Answer:
Option C -> Option CQuick Check:
PCA reduces dimensions, keeps variance. [OK]
Hint: PCA reduces dimensions, keeps variance. [OK]
Common Mistakes:
