Practice
1. What is the time complexity of a single iteration of gradient descent for linear regression with n samples and d features?
easy
Solution
Step 1: Identify operations in a single iteration
Each iteration involves matrix multiplication and gradient computation.Step 2: Calculate complexity
Matrix multiplication and gradient computation both require O(nd) operations.Final Answer:
Option C -> Option CQuick Check:
Matrix operations scale with samples and features. [OK]
Hint: Matrix operations scale with samples and features. [OK]
Common Mistakes:
2. 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:
3. In the context of implementing linear regression with gradient descent, how would you handle a dataset with missing values?
medium
Solution
Step 1: Consider impact of missing values
Ignoring or zero-filling can bias results; removing samples reduces data.Step 2: Choose appropriate imputation
Mean imputation is a common strategy that maintains dataset size and reduces bias.Final Answer:
Option A -> Option AQuick Check:
Mean imputation balances bias and data retention. [OK]
Hint: Mean imputation balances bias and data retention. [OK]
Common Mistakes:
4. In the context of logistic regression, which approach is correct for handling a dataset with highly imbalanced classes?
medium
Solution
Step 1: Identify the problem with imbalanced classes
Imbalanced classes can lead to biased predictions towards the majority class.Step 2: Choose a method to address imbalance
SMOTE (Synthetic Minority Over-sampling Technique) is effective for balancing datasets.Final Answer:
Option B -> Option BQuick Check:
SMOTE balances classes effectively [OK]
Hint: SMOTE balances classes effectively [OK]
Common Mistakes:
5. How would you apply sinusoidal positional encoding in a transformer model for a sequence of variable length?
medium
Solution
Step 1: Consider variable sequence lengths
Each sequence should have positional encoding applied based on its actual length to maintain positional information.Step 2: Eliminate wrong options
Pad all sequences to the maximum length and apply encoding. is inefficient and may introduce unnecessary padding. Apply encoding only to the first few positions of each sequence. ignores the rest of the sequence. Use a fixed-length encoding for all sequences, regardless of length. loses positional information for longer sequences.Final Answer:
Option B -> Option BQuick Check:
Encode based on actual sequence length. [OK]
Hint: Encode based on actual sequence length. [OK]
Common Mistakes:
