Practice
1. What does the following Python code output when implementing logistic regression with a sigmoid activation function?
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
z = np.array([0, 2, -2])
output = sigmoid(z)
print(output)easy
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]
Hint: Sigmoid(0)=0.5, Sigmoid(2)ā0.88, Sigmoid(-2)ā0.12 [OK]
Common Mistakes:
2. What is the time complexity of calculating the mean Average Precision (mAP) for a single image with N predicted bounding boxes and M ground truth boxes?
easy
Solution
Step 1: Understand the Process
For each predicted box, IoU is calculated with each ground truth box, leading to N * M comparisons.Step 2: Determine Complexity
Each comparison is constant time, so the overall complexity is O(N * M).Final Answer:
Option C -> Option CQuick Check:
IoU comparisons drive complexity [OK]
Hint: IoU comparisons drive complexity [OK]
Common Mistakes:
3. You implemented stratified K-Fold cross-validation but notice class imbalance in some folds. What is the most likely cause?
medium
Solution
Step 1: Identify stratification issue
Stratification ensures class distribution is preserved in each fold.Step 2: Eliminate wrong options
Incorrect number of splits and D relate to fold count, not class distribution. Data shuffling before splitting affects randomness, not stratification.Final Answer:
Option A -> Option AQuick Check:
Check stratification parameter for class balance. [OK]
Hint: Check stratification parameter for class balance. [OK]
Common Mistakes:
4. A logistic regression model is not converging during training. Which line in the code is most likely causing the issue?
import numpy as np
# Initialize weights
weights = np.zeros((m, 1))
# Training loop
for epoch in range(epochs):
# Compute predictions
predictions = 1 / (1 + np.exp(-np.dot(X, weights)))
# Compute gradient
gradient = np.dot(X.T, (predictions - y)) / n
# Update weights
weights -= learning_rate * gradientmedium
Solution
Step 1: Identify potential issues
Convergence issues often arise from incorrect weight updates or learning rate problems.Step 2: Analyze weight update line
If learning_rate is too high, weights update too aggressively, causing divergence.Final Answer:
Option A -> Option AQuick Check:
Check learning rate in weight updates [OK]
Hint: Check learning rate in weight updates [OK]
Common Mistakes:
5. How can you optimize the NDCG calculation for large datasets?
hard
Solution
Step 1: Identify Bottlenecks
Calculating log values repeatedly can be computationally expensive.Step 2: Optimize Calculation
Precomputing log values for positions reduces redundant calculations.Final Answer:
Option C -> Option CQuick Check:
Precompute logs for efficiency. [OK]
Hint: Precompute logs for efficiency. [OK]
Common Mistakes:
