Practice
1.
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([1, 2, 3, 4, 5, 6])
y = np.array([0, 0, 1, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, stratify=y)
print(y_train)easy
Solution
Step 1: Understand stratification
Stratification ensures that the class distribution in the train and test sets is similar to the original dataset.Step 2: Calculate class distribution
Original y has 3 zeros and 3 ones. With stratification, y_train should have 1 zero and 2 ones.Final Answer:
Option D -> Option DQuick Check:
Stratify maintains class distribution. [OK]
Hint: Stratify maintains class distribution. [OK]
Common Mistakes:
2. In a pipeline that includes flipping, cropping, and normalizing images, where should normalization be applied for best results?
medium
Solution
Step 1: Understand the impact of operations
Normalization should be the last step to ensure consistent scaling.Step 2: Evaluate each option
Applying normalization last ensures it accounts for all transformations.Final Answer:
Option D -> Option DQuick Check:
Normalize last for consistent scaling. [OK]
Hint: Normalize last for consistent scaling. [OK]
Common Mistakes:
3. In the context of implementing linear regression with gradient descent, how would you handle a dataset with missing values?
medium
Solution
Step 1: Consider impact of missing values
Ignoring or zero-filling can bias results; removing samples reduces data.Step 2: Choose appropriate imputation
Mean imputation is a common strategy that maintains dataset size and reduces bias.Final Answer:
Option A -> Option AQuick Check:
Mean imputation balances bias and data retention. [OK]
Hint: Mean imputation balances bias and data retention. [OK]
Common Mistakes:
4. How would you adapt the ROC curve implementation to handle multi-class classification?
medium
Solution
Step 1: Understand multi-class ROC adaptation
One-vs-rest strategy is commonly used to compute ROC for each class separately.Step 2: Eliminate wrong options
Use the average of ROC curves for each class. is incorrect as averaging doesn't apply directly, Options C and D are mathematically incorrect.Final Answer:
Option A -> Option AQuick Check:
Use one-vs-rest for multi-class ROC [OK]
Hint: Use one-vs-rest for multi-class ROC [OK]
Common Mistakes:
5. How can you optimize the computation of the ROC curve for a large dataset?
hard
Solution
Step 1: Identify optimization strategies
Parallel processing can speed up computation by handling different thresholds simultaneously.Step 2: Eliminate wrong options
Use a smaller batch size for computation. doesn't address the core computation, Use a subset of data to approximate the ROC curve. may reduce accuracy, Use a more efficient sorting algorithm for the scores. is limited by sorting algorithm constraints.Final Answer:
Option D -> Option DQuick Check:
Parallel processing speeds up ROC computation [OK]
Hint: Parallel processing speeds up ROC computation [OK]
Common Mistakes:
