Practice
1. In a binary classification problem where false positives are costly, which metric should be prioritized?
easy
Solution
Step 1: Identify the cost concern.
False positives are costly, so we need to minimize them.Step 2: Choose the metric that minimizes false positives.
Precision is the metric that focuses on minimizing false positives.Final Answer:
Option A -> Option AQuick Check:
Precision minimizes false positives. [OK]
Hint: Precision minimizes false positives. [OK]
Common Mistakes:
2.
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
print(X_train.shape, X_test.shape)What is the output of this code snippet?easy
Solution
Step 1: Understand train_test_split behavior.
With test_size=0.5, the data is split equally into train and test sets.Step 2: Calculate expected shapes.
Original data has 4 samples, so both train and test sets will have 2 samples each.Final Answer:
Option C -> Option CQuick Check:
Equal split with test_size=0.5. [OK]
Hint: Equal split with test_size=0.5. [OK]
Common Mistakes:
3. In the context of evaluating a recommendation system, which of the following best describes why offline evaluation metrics might disagree with online performance?
easy
Solution
Step 1: Understand the difference between offline and online evaluation.
Offline evaluation uses historical data and predefined metrics, while online evaluation captures real-time user interactions.Step 2: Eliminate wrong options.
Offline metrics are always more accurate than online metrics. is incorrect because offline metrics are not inherently more accurate. Online metrics are biased due to data leakage. is incorrect because online metrics are not biased due to data leakage; they reflect real-world interactions. Offline metrics are influenced by server latency. is incorrect because server latency affects online performance, not offline metrics.Final Answer:
Option D -> Option DQuick Check:
Offline misses real user dynamics. [OK]
Hint: Offline misses real user dynamics. [OK]
Common Mistakes:
4.
import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])
model = DecisionTreeClassifier()
scores = cross_val_score(model, X, y, cv=2)
print(scores)What does this code output?easy
Solution
Step 1: Understand cross-validation output
Cross-validation with cv=2 splits the data into two folds, returning an array of two scores.Step 2: Eliminate wrong options
An error because the dataset is too small for cross-validation. is incorrect because the code runs without error. A single accuracy score for the entire dataset. is incorrect because cross-validation returns multiple scores. An array of four accuracy scores, one for each data point. is incorrect because the number of scores equals the number of folds, not data points.Final Answer:
Option A -> Option AQuick Check:
Cross-validation returns scores per fold. [OK]
Hint: Cross-validation returns scores per fold. [OK]
Common Mistakes:
5. After applying PCA to your dataset, you notice that the variance explained by the components is much lower than expected. What is the most likely cause?
medium
Solution
Step 1: Identify the role of feature scaling in PCA
PCA is sensitive to the scale of the data.Step 2: Evaluate each option
Missing values would cause errors, not low variance. Too many components would explain more variance, not less. A small dataset affects generalization, not variance explained.Final Answer:
Option C -> Option CQuick Check:
Standardize features before PCA [OK]
Hint: Standardize features before PCA [OK]
Common Mistakes:
