Practice
1.
import numpy as np
from sklearn.preprocessing import StandardScaler
X = np.array([[1, 2], [3, 4], [5, 6]])
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled.mean(axis=0))What does this code output?easy
Solution
Step 1: Understand standardization.
StandardScaler standardizes features by removing the mean and scaling to unit variance.Step 2: Calculate the mean of standardized data.
After standardization, the mean of each feature should be 0.Final Answer:
Option C -> Option CQuick Check:
StandardScaler centers data to mean 0. [OK]
Hint: StandardScaler centers data to mean 0. [OK]
Common Mistakes:
2. Given the following Python code snippet, what will be the output?
import numpy as np
business_goals = np.array(['increase sales', 'reduce churn', 'improve satisfaction'])
ml_problems = np.array(['classification', 'regression', 'clustering'])
result = np.char.add(business_goals, ml_problems)
print(result)easy
Solution
Step 1: Understand the operation
The np.char.add function concatenates corresponding elements of two arrays element-wise.Step 2: Eliminate wrong options
['increase sales', 'reduce churn', 'improve satisfaction'] and C are incorrect because they ignore the concatenation operation. Throws an error due to incompatible types is incorrect because np.char.add handles string arrays correctly.Final Answer:
Option A -> Option AQuick Check:
np.char.add concatenates strings element-wise. [OK]
Hint: np.char.add concatenates strings element-wise. [OK]
Common Mistakes:
3. You have a dataset with a large number of features and limited computational resources. Which feature selection method is most appropriate?
medium
Solution
Step 1: Consider computational efficiency.
Filter methods are computationally inexpensive as they do not involve training models.Step 2: Eliminate wrong options.
Wrapper methods and recursive feature elimination are computationally intensive. Embedded methods require model training, which can be resource-heavy.Final Answer:
Option D -> Option DQuick Check:
Filter = low cost, no model. [OK]
Hint: Filter methods are computationally cheap. [OK]
Common Mistakes:
4. When should you avoid using Naive Bayes despite its simplicity and speed?
medium
Solution
Step 1: Identify Naive Bayes Limitations
Naive Bayes assumes feature independence given the class label.Step 2: Evaluate Each Option
When the dataset is very large. is incorrect because Naive Bayes handles large datasets well. When you need a probabilistic output. is incorrect because Naive Bayes provides probabilistic outputs. When the dataset has missing values. is incorrect because Naive Bayes can handle missing values with some preprocessing.Final Answer:
Option D -> Option DQuick Check:
Correlated features break Naive Bayes. [[check]]
Hint: Correlated features break Naive Bayes. [[check]]
Common Mistakes:
5. How would you adapt dropout for a recurrent neural network (RNN) to prevent overfitting without disrupting temporal dependencies?
hard
Solution
Step 1: Understand dropout in RNNs
Using the same dropout mask at each time step helps maintain temporal dependencies.Step 2: Eliminate wrong options
Apply dropout to the input and output layers only. is incorrect because it doesn't address hidden state dropout. Apply dropout to the hidden states at each time step. is incorrect because applying dropout to hidden states at each time step can disrupt dependencies. Increase the dropout rate progressively over time. is incorrect because increasing dropout rate over time is not a standard practice and can lead to underfitting.Final Answer:
Option D -> Option DQuick Check:
Same mask preserves RNN dependencies. [OK]
Hint: Same mask preserves RNN dependencies. [OK]
Common Mistakes:
