Practice
Solution
Step 1: Understand ROC computation
ROC curve computation involves sorting the scores, which is O(n log n).Step 2: Eliminate wrong options
O(n^2) is incorrect as it suggests quadratic complexity, O(n) suggests linear complexity which ignores sorting, and O(log n) is too low.Final Answer:
Option A -> Option AQuick Check:
ROC curve involves sorting, hence O(n log n) [OK]
import torch
import torch.nn.functional as F
queries = torch.tensor([[1.0, 0.0], [0.0, 1.0]])
keys = torch.tensor([[1.0, 0.0], [0.0, 1.0]])
values = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
scores = torch.matmul(queries, keys.T) / torch.sqrt(torch.tensor(2.0))
attention_weights = F.softmax(scores, dim=-1)
output = torch.matmul(attention_weights, values)
print(output)Solution
Step 1: Calculate scores
Scores are calculated as dot product of queries and keys, divided by sqrt(2).Step 2: Apply softmax
Softmax is applied to scores, resulting in identity matrix since queries and keys are orthogonal.Step 3: Calculate output
Output is the same as values because attention weights are identity matrix.Final Answer:
Option A -> Option AQuick Check:
Orthogonal queries/keys -> identity attention weights [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: Consider parallel processing
Parallel processing can significantly speed up tree construction on large datasets.Step 2: Eliminate wrong options
Complex criteria (A) slow down; increasing depth (C) can overfit; single-threaded (D) is less efficient.Final Answer:
Option A -> Option AQuick Check:
Large data? Use parallel processing [OK]
Solution
Step 1: Identify optimization strategies
Approximate nearest neighbors can significantly speed up queries in large datasets.Step 2: Evaluate other options
A: Balancing helps but isn't enough for large datasets. B: Increasing dimensions worsens performance. D: Reducing data points isn't always feasible.Final Answer:
Option B -> Option BQuick Check:
Approximate neighbors speed up KD-Tree [OK]
