Practice
1. What is the output of the following Python code snippet using NumPy for logistic regression log-odds calculation?
import numpy as np
coefficients = np.array([0.5, -0.25])
features = np.array([2, 3])
log_odds = np.dot(coefficients, features)
print(log_odds)easy
Solution
Step 1: Calculate the dot product.
The dot product is calculated as (0.5 * 2) + (-0.25 * 3) = 1.0 - 0.75 = 0.25.Step 2: Identify the correct output.
-0.25 is correct because the calculation results in 0.25. 1.25 is incorrect as it suggests a miscalculation. 0.25 is incorrect due to a sign error. 2.75 is incorrect due to a misunderstanding of dot product.Final Answer:
Option A -> Option AQuick Check:
Dot product = sum of products [OK]
Hint: Dot product = sum of products [OK]
Common Mistakes:
2. In the context of model debugging, which of the following is a common symptom of data leakage?
easy
Solution
Step 1: Identify data leakage symptoms
Data leakage often results in a model that performs well on both training and validation sets because it has inadvertently learned from the validation data.Step 2: Eliminate wrong options
Options A, B, and C indicate poor generalization or overfitting, not data leakage.Final Answer:
Option D -> Option DQuick Check:
Data leakage = too good to be true [OK]
Hint: Data leakage = too good to be true [OK]
Common Mistakes:
3. In the context of Transformer architecture, what is the primary purpose of self-attention?
easy
Solution
Step 1: Understand self-attention's role
Self-attention allows the model to weigh the importance of different words in a sequence, capturing dependencies regardless of their position.Step 2: Eliminate wrong options
To reduce the dimensionality of input data is incorrect because self-attention does not reduce dimensionality. To encode positional information of words in a sequence is incorrect as positional encoding handles positional information. To improve the model's ability to generalize to unseen data is incorrect because self-attention focuses on sequence dependencies, not generalization.Final Answer:
Option A -> Option AQuick Check:
Self-attention captures word dependencies. [OK]
Hint: Self-attention captures word dependencies. [OK]
Common Mistakes:
4.
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(1, input_dim=2, activation='relu'))
model.add(Dense(1, activation='relu'))
weights = model.get_weights()
print([w.shape for w in weights])What does this code output?easy
Solution
Step 1: Analyze the network structure
The first layer has 2 inputs and 1 output, so weights are (2, 1) and biases are (1,). The second layer has 1 input and 1 output, so weights are (1, 1) and biases are (1,).Step 2: Eliminate wrong options
[(2, 1), (1,), (1, 2), (1,)] is incorrect because the second layer's weights should be (1, 1). [(1, 2), (1,), (1, 1), (1,)] is incorrect because the first layer's weights should be (2, 1). [(2, 1), (2,), (1, 1), (1,)] is incorrect because the first layer's biases should be (1,).Final Answer:
Option A -> Option AQuick Check:
Check layer dimensions match input/output. [OK]
Hint: Check layer dimensions match input/output. [OK]
Common Mistakes:
5. When monitoring an ML model in production, which approach is better for detecting data drift and why?
medium
Solution
Step 1: Identify effective drift detection
Monitoring statistical properties helps detect subtle changes in input data.Step 2: Eliminate wrong options
Use a static threshold on model accuracy. is reactive, not proactive. Rely on user feedback to identify issues. is unreliable and subjective. Increase the frequency of model retraining. addresses performance decay, not drift detection.Final Answer:
Option A -> Option AQuick Check:
Monitor input stats for drift detection [OK]
Hint: Monitor input stats for drift detection [OK]
Common Mistakes:
