Practice
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(len(X_train), len(X_test))Solution
Step 1: Calculate the split sizes
With a test_size of 0.2, 20% of 10 samples go to the test set, i.e., 2 samples.Step 2: Determine the training set size
The remaining 80% (8 samples) go to the training set.Final Answer:
Option B -> Option BQuick Check:
80% train, 20% test split. [OK]
import numpy as np
data = np.array([1, 2, 3, 4, 5])
# Simulate offline data processing
processed_data = data * 2
print(processed_data)Solution
Step 1: Understand the code operation
The code multiplies each element of the array by 2.Step 2: Calculate the expected output
Each element in the array [1, 2, 3, 4, 5] is multiplied by 2, resulting in [2, 4, 6, 8, 10].Final Answer:
Option B -> Option BQuick Check:
Array * 2 doubles each element. [OK]
Solution
Step 1: Analyze the impact of standardization on model performance.
Standardization centers data around zero, which can affect models sensitive to feature means.Step 2: Identify the potential issue.
Some models may perform poorly if they rely on the original mean of the data.Final Answer:
Option A -> Option AQuick Check:
Model sensitive to mean? Standardization affects it. [OK]
Solution
Step 1: Identify the constraint
Gradient Descent is more suitable for large datasets that don't fit in memory because it can process data in batches.Step 2: Eliminate wrong options
Least Squares is efficient for small datasets (A), interpretability is not a deciding factor (C), and noise handling depends on regularization, not the optimization method (D).Final Answer:
Option C -> Option CQuick Check:
Gradient Descent handles large datasets in batches. [OK]
Solution
Step 1: Understand K-Means limitations
K-Means is not suitable for categorical data as it relies on Euclidean distance.Step 2: Choose the right adaptation
K-Modes is designed for clustering categorical data, making it the best choice.Final Answer:
Option B -> Option BQuick Check:
K-Modes for categorical data [OK]
