Practice
import numpy as np
# Simulate A/B test results
A_results = np.array([1, 0, 1, 1, 0])
B_results = np.array([0, 1, 0, 0, 1])
# Calculate mean conversion rates
A_mean = np.mean(A_results)
B_mean = np.mean(B_results)
# Determine which variant is better
better_variant = 'A' if A_mean > B_mean else 'B'
print(better_variant)What does this code output?Solution
Step 1: Calculate means
A_mean = 0.6, B_mean = 0.2Step 2: Compare means
A_mean > B_mean, so 'A' is printed.Final Answer:
A -> AQuick Check:
Calculate means, compare, print. [OK]
W after backpropagation?import torch
W = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True)
x = torch.tensor([1.0, 2.0])
y = W @ x
loss = y.sum()
loss.backward()Solution
Step 1: Determine the gradient shape
The gradient ofWwill have the same shape asW, which is (2, 2).Step 2: Eliminate wrong options
(2,) is incorrect because it suggests a vector shape. (2, 1) and D are incorrect because they suggest mismatched dimensions.Final Answer:
Option A -> Option AQuick Check:
Gradient shape matches tensor shape. [OK]
import numpy as np
relevance_scores = [3, 2, 3, 0, 1, 2]
ideal_dcg = np.sum([3/np.log2(i+2) for i in range(len(relevance_scores))])
print(round(ideal_dcg, 2))Solution
Step 1: Calculate the ideal DCG
Use the formula DCG = ฮฃ(rel_i / log2(i+2)) for each relevance score.Step 2: Perform the calculation
3/1 + 2/1.585 + 3/2 + 0/2.322 + 1/2.585 + 2/2.807 = 6.86.Final Answer:
Option B -> Option BQuick Check:
DCG uses log2(i+2) for position i. [OK]
from sklearn.metrics import roc_auc_score
y_true = [0, 0, 0, 0, 1]
y_scores = [0.1, 0.2, 0.3, 0.4, 0.9]
roc_auc = roc_auc_score(y_true, y_scores)
print(roc_auc)Solution
Step 1: Calculate ROC-AUC
ROC-AUC measures the ability to distinguish between classes. Here, the positive class is perfectly ranked higher than the negative class.Step 2: Eliminate wrong options
0.5 would indicate random guessing. 0.75 and 0.9 are incorrect as the positive class is perfectly ranked.Final Answer:
Option A -> Option AQuick Check:
Perfect ranking gives ROC-AUC of 1.0. [OK]
Solution
Step 1: Analyze the effect of regularization on SVM
A low regularization parameter allows more flexibility, leading to overfitting.Step 2: Eliminate wrong options
The model is overfitting due to a high regularization parameter is incorrect because a high regularization parameter reduces overfitting. The model is underfitting due to a low regularization parameter is incorrect because a low regularization parameter does not cause underfitting. The model is underfitting due to a high regularization parameter is incorrect because a high regularization parameter causes underfitting, not overfitting.Final Answer:
Option D -> Option DQuick Check:
Low regularization can lead to overfitting [OK]
