Practice
import numpy as np
def positional_encoding(position, d_model):
angle_rads = np.arange(position)[:, np.newaxis] / np.power(10000, (2 * (np.arange(d_model)[np.newaxis, :] // 2)) / np.float32(d_model))
angle_rads[:, 0::2] = np.sin(angle_rads[:, 0::2])
angle_rads[:, 1::2] = np.cos(angle_rads[:, 1::2])
return angle_rads
pe = positional_encoding(4, 4)
print(pe)Solution
Step 1: Understand the code logic
The code generates a matrix where each row corresponds to a position and each column to a dimension, filled with sinusoidal values.Step 2: Eliminate wrong options
A 4x4 matrix with all zeros is incorrect because the matrix is not filled with zeros. A 4x4 identity matrix is incorrect because the matrix is not an identity matrix. A 4x4 matrix with random values is incorrect because the values are not random but deterministic sinusoidal values.Final Answer:
Option A -> Option AQuick Check:
Sinusoidal encoding alternates sine/cosine. [OK]
Solution
Step 1: Analyze Tree Training Complexity
Each decision tree in a Random Forest is trained on a subset of features and samples.Step 2: Determine Complexity
Training a decision tree typically involves sorting, leading to O(n * m * log(n)) complexity.Final Answer:
Option D -> Option DQuick Check:
Tree training involves sorting [OK]
Solution
Step 1: Understand Robust Scaling
Robust Scaling uses the median and IQR, which reduces the influence of outliers.Step 2: Identify the Issue
If outliers are important, reducing their influence can harm model performance.Final Answer:
Option D -> Option DQuick Check:
Robust Scaling reduces outlier impact. [OK]
Solution
Step 1: Understand text preprocessing needs
In text classification, irrelevant words can add noise.Step 2: Evaluate preprocessing steps
Removing stop words (Removing stop words) reduces noise and improves performance. Options A and C are less relevant as MultinomialNB doesn't require normalized or scaled features. Applying PCA for dimensionality reduction is unnecessary as PCA isn't typically used for text data.Final Answer:
Option C -> Option CQuick Check:
Remove stop words to reduce noise in text data. [OK]
Solution
Step 1: Identify the role of stratification
Stratification ensures class distribution is maintained across splits.Step 2: Diagnose the issue
If the stratify parameter is not set correctly, class distribution will not be maintained.Final Answer:
Option B -> Option BQuick Check:
Check stratify parameter for distribution issues. [OK]
