Practice
1.
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
y = np.array([1, 0, 1])
selector = SelectKBest(score_func=f_classif, k=2)
X_new = selector.fit_transform(X, y)
print(X_new)What does the above code output?easy
Solution
Step 1: Understand SelectKBest.
SelectKBest selects the top k features based on the highest scores from the scoring function.Step 2: Determine the output.
f_classif scores features based on ANOVA F-value. Here, features 2 and 3 have the highest scores.Final Answer:
Option A -> Option AQuick Check:
Top k features by score. [OK]
Hint: SelectKBest picks top k features by score. [OK]
Common Mistakes:
2. A model trained on a dataset with engineered features is underperforming on the validation set. What is the most likely cause?
medium
Solution
Step 1: Analyze the symptoms of underperformance.
Underperformance on validation suggests overfitting or poor generalization.Step 2: Evaluate the role of feature engineering.
Over-engineered features (C) can lead to overfitting, especially if they capture noise. Normalization (B) affects convergence but not generalization directly. Model complexity (A, D) is less likely the issue if features are the focus.Final Answer:
Option B -> Option BQuick Check:
Over-engineered features often lead to overfitting. [OK]
Hint: Over-engineered features often lead to overfitting. [OK]
Common Mistakes:
3. You have a model that is overfitting. Which approach is more suitable to address this issue?
medium
Solution
Step 1: Identify methods to combat overfitting
Dropout is a regularization technique that helps prevent overfitting by randomly dropping units during training.Step 2: Eliminate wrong options
Increase the model complexity by adding more layers. increases overfitting risk, Reduce the size of the training dataset. reduces data, worsening generalization, and Use a smaller learning rate. affects convergence speed, not overfitting directly.Final Answer:
Option A -> Option AQuick Check:
Dropout reduces overfitting [OK]
Hint: Dropout reduces overfitting [OK]
Common Mistakes:
4. You are tasked with reducing the dimensionality of a dataset for a clustering task. The dataset contains both numerical and categorical features. Which approach should you take?
hard
Solution
Step 1: Consider the nature of the data
Dimensionality reduction techniques like PCA and t-SNE require numerical input.Step 2: Evaluate the options
PCA cannot handle categorical data directly. t-SNE is computationally expensive and not ideal for mixed data types. LDA is not suitable for unsupervised clustering tasks.Final Answer:
Option A -> Option AQuick Check:
UMAP for mixed data types [OK]
Hint: UMAP for mixed data types [OK]
Common Mistakes:
5. You are tasked with designing a system to detect fraudulent transactions. Which approach is most appropriate given the need for adaptability to new fraud patterns?
hard
Solution
Step 1: Consider the need for adaptability.
Fraud patterns change over time, requiring a system that can learn and adapt.Step 2: Evaluate the options for adaptability.
Only a machine learning model that can be retrained offers the necessary adaptability.Final Answer:
Option D -> Option DQuick Check:
ML adapts, rules are static. [OK]
Hint: ML adapts, rules are static. [OK]
Common Mistakes:
