Practice
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
z = np.array([0, 2, -2])
output = sigmoid(z)
print(output)Solution
Step 1: Calculate sigmoid for each element
Sigmoid function is applied element-wise:sigmoid(0) = 0.5,sigmoid(2) โ 0.88,sigmoid(-2) โ 0.12.Step 2: Check precision of calculations
Common mistake is rounding errors. Correct values are[0.5, 0.880797, 0.119203], rounded to[0.5, 0.88, 0.12].Final Answer:
Option C -> Option CQuick Check:
Sigmoid(0)=0.5, Sigmoid(2)โ0.88, Sigmoid(-2)โ0.12 [OK]
from sklearn.metrics import roc_curve
import numpy as np
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
print(fpr, tpr, thresholds)Solution
Step 1: Understand ROC curve output
The ROC curve function returns false positive rates (fpr), true positive rates (tpr), and thresholds.Step 2: Analyze the code
Given the scores and true labels, the ROC curve is calculated correctly, resulting in fpr, tpr, and thresholds as in array([0. , 0.5, 1. ]), array([0. , 0.5, 1. ]), array([0.8, 0.35, 0.1]).Final Answer:
Option C -> Option CQuick Check:
ROC curve outputs fpr, tpr, thresholds [OK]
Solution
Step 1: Analyze operations
Softmax involves computing exponentials and a sum, both linear in n.Step 2: Determine complexity
Each operation is O(n), so overall complexity is O(n).Final Answer:
Option D -> Option DQuick Check:
Softmax is linear in input size [OK]
Solution
Step 1: Identify the Symptom
High mAP values suggest too many matches are considered correct.Step 2: Analyze Each Option
Incorrect IoU threshold for positive matches: A low IoU threshold can cause false positives to be counted as true positives, inflating mAP. Using precision instead of recall in calculations: Would affect recall, not mAP directly. Not normalizing the precision values: Would affect the scale, not the value. Including false negatives in the precision calculation: Would lower precision, not increase it.Final Answer:
Option B -> Option BQuick Check:
Check IoU threshold for false positives [OK]
Solution
Step 1: Identify negative values cause
Cross-entropy loss should be non-negative; negative values suggest log issues.Step 2: Check log application
Log applied to values outside (0,1) can cause negatives.Final Answer:
Option B -> Option BQuick Check:
Log of non-probabilities causes negatives [OK]
