Question 21 · Model Evaluation and Overfitting · hard
You train a linear regression model on housing data with features [area_sqft, bedrooms, distance_to_city]. The model achieves R² = 0.95 on training data but R² = 0.52 on test data. How would you predict what this performance gap indicate?
The model is underfitting because 3 features are insufficient for any regression task
Underfitting — R² = 0.95 on training is too low, meaning the model is too simple to capture the relationship
The test set is corrupted — a well-trained model with R² = 0.95 should always maintain similar performance on test data
Overfitting — the model memorized training patterns (including noise) but fails to generalize; it needs regularization or more training data
Answer: D. Overfitting — the model memorized training patterns (including noise) but fails to generalize; it needs regularization or more training data
ExplanationA large gap between training performance (R² = 0.95) and test performance (R² = 0.52) is the classic signature of overfitting: the model has learned patterns specific to the training data, including its noise, that don't generalize to new data. Common fixes include L1/L2 regularization, reducing model complexity, or gathering more training data. The claim that three features are inherently insufficient for any regression task is false — the problem here isn't a lack of model capacity, since the model already fits the training data essentially perfectly. The claim that a training R² of 0.95 is "too low" has it backwards — that high a training score means the model captures the training relationship very well; underfitting would instead show a LOW training R², not a high one. A corrupted test set is also not indicated — test performance falling below training performance is expected in general, and it's the SIZE of that gap (0.95 vs 0.52) that signals overfitting rather than pointing to bad data.
Question 22 · Matrix Operations and Linear Algebra · hard
Given a matrix A of size 4×6, where the rows represent 4 data samples and the columns represent 6 features, what is the maximum possible rank of A?
24, from multiplying dimensions (4 x 6 = 24) confusing rank with matrix size
6, from thinking rank equals the number of columns (4x6 matrix has 6 columns)
4, because the rank cannot exceed the minimum of the row and column dimensions
40, from adding the two dimensions and multiplying by the row count (4+6=10, then 10 x 4 = 40) instead of applying the min(rows, cols) rule
Answer: C. 4, because the rank cannot exceed the minimum of the row and column dimensions
ExplanationFirst, the rank of any matrix is bounded by the minimum of its dimensions. For a 4x6 matrix, the maximum rank is min(4, 6) = 4. Then, rank represents the number of linearly independent rows or columns; since there are only 4 rows, you cannot have more than 4 linearly independent rows. This is fundamental in linear algebra and impacts feature dimensionality and model complexity in machine learning applications.
Question 23 · Matrix Operations and Linear Algebra · hard
A 2×2 rotation matrix R rotates points by 90 degrees counterclockwise in the plane. When you compute det(R - λI) = 0 to find eigenvalues, what are the eigenvalues of R, and what does this tell you about the geometric nature of rotation?
Real eigenvalues 0 and 1, from confusing rotation with a singular matrix having fixed eigenvectors
Eigenvalues ±1, from thinking 90-degree rotation squares to identity (true for repeated application, not eigenvalues)
Complex eigenvalues ±i, indicating 90-degree rotation has no real fixed vectors (rotates all directions, not along principal axes)
All 1s, from assuming rotation preserves magnitude and direction, confusing with identity transformation
Answer: C. Complex eigenvalues ±i, indicating 90-degree rotation has no real fixed vectors (rotates all directions, not along principal axes)
ExplanationFirst, for a 2D rotation matrix by 90 degrees R = [[0, -1], [1, 0]], the characteristic polynomial is det(R - λI) = λ^2 + 1 = 0, yielding eigenvalues λ = ±i (complex). Complex eigenvalues indicate that rotation has no real eigenvectors—no direction remains unchanged after the rotation. Then, this concept is important in understanding geometric transformations in computer vision and data augmentation where rotations don't have stable feature directions. This is exactly what distinguishes rotation from scaling or reflection: because no real eigenvector exists, R cannot be diagonalized over the reals, confirming that a 90-degree rotation genuinely turns every direction rather than stretching or fixing any axis.
Question 24 · Probability and Statistics · hard
A diagnostic test for disease has sensitivity 0.95 (true positive rate) and specificity 0.92 (true negative rate). If disease prevalence is 0.02, What happens when you evaluate the probability a positive test result actually indicates disease P(disease|positive)?
0.019 or 1.9%, from computing only sensitivity x prior without dividing by the denominator
0.084 or 8.4%, from inverting the formula to compute P(negative|test+) instead of P(disease|test+)
0.95 or 95%, from assuming posterior equals sensitivity and ignoring base rate effects entirely
Answer: C. P(disease|positive) = (0.95 × 0.02) / [(0.95 × 0.02) + (0.08 × 0.98)] ≈ 0.195, showing base rate neglect leads to overconfidence
ExplanationFirst, using Bayes' theorem: P(disease|positive) = P(positive|disease) × P(disease) / P(positive). Here: P(positive|disease) = sensitivity = 0.95, P(disease) = 0.02, P(¬disease) = 0.98, P(positive|¬disease) = 1 - specificity = 0.08. Then, so P(positive) = (0.95 × 0.02) + (0.08 × 0.98) = 0.019 + 0.0784 = 0.0974. Therefore P(disease|positive) = (0.95 × 0.02) / 0.0974 ≈ 0.195. Even with high sensitivity/specificity, low disease prevalence (0.02) makes false positives common. Finally, this illustrates base rate neglect in medical ML and why positive predictive value matters more than sensitivity alone.
Question 25 · Decision Trees and Ensemble Methods · hard
In Gradient Boosting, each new tree is trained to predict the residual of the current ensemble, and its output is added using a learning rate η via the update rule F_m(x) = F_{m-1}(x) + η·h_m(x). For a single training point with true value y = 90, the initial model predicts F₀ = 50, giving a residual of 40. Tree₁ is trained on this residual and, for this particular point, predicts h₁ = 40 exactly. If the learning rate is η = 0.25, what is the new residual for this data point after Tree₁'s contribution is added?
F₁ evaluates to 60, so the residual falls to 30, since y − F₁ = 90 − (50 + 0.25×40) = 30.
Adding Tree₁'s full residual prediction closes the gap completely, driving the residual to 0 regardless of the learning rate's value.
Scaling the original residual by the learning rate directly yields a new residual of 10, since 0.25 × 40 = 10 is treated as the leftover error.
No meaningful correction occurs until the learning rate reaches 1, so the residual remains unchanged at 40 after this round.
Answer: A. F₁ evaluates to 60, so the residual falls to 30, since y − F₁ = 90 − (50 + 0.25×40) = 30.
ExplanationThe gradient boosting update rule is F₁ = F₀ + η·h₁. Substituting the given values: F₁ = 50 + 0.25 × 40 = 50 + 10 = 60. The residual after this round is y − F₁ = 90 − 60 = 30. This shows why the learning rate matters: it scales down Tree₁'s correction so the ensemble moves only part-way toward closing the gap, leaving 30 of the original 40-point residual still to be corrected by later trees. The claim that adding Tree₁'s full prediction closes the gap completely and drives the residual to 0 ignores the learning rate entirely, effectively treating η as 1 instead of 0.25. The claim that scaling the residual by the learning rate directly gives a new residual of 10 confuses the amount subtracted (η × 40 = 10) with the amount that remains (40 − 10 = 30). The claim that no correction occurs until the learning rate reaches 1 misunderstands learning rate as an on/off gate rather than a continuous scaling factor — even a small η > 0 produces an immediate, if partial, update on every round.
Question 26 · Neural Network Fundamentals · hard
In a deep neural network with 10 hidden layers using sigmoid activation σ(x) = 1/(1+e^(-x)), where the maximum derivative of sigmoid is 0.25, what happens to gradients during backpropagation and why does this cause training failure?
Gradients shrink exponentially: each layer multiplies by at most 0.25, so after 10 layers the gradient is at most 0.25^10 ≈ 9.5×10⁻⁷, making early layer weights effectively untrainable
Gradients remain constant through layers because the chain rule preserves magnitude — each sigmoid derivative is balanced by the weight magnitudes, maintaining gradient flow regardless of depth
Gradients grow exponentially because sigmoid's derivative is always greater than 1 in the saturation region, causing numerical overflow after several layers of chain rule multiplication
Gradients oscillate between positive and negative values across layers because sigmoid's output range [0,1] causes alternating sign flips in the derivative chain, not magnitude reduction
Answer: A. Gradients shrink exponentially: each layer multiplies by at most 0.25, so after 10 layers the gradient is at most 0.25^10 ≈ 9.5×10⁻⁷, making early layer weights effectively untrainable
ExplanationFirst, the vanishing gradient problem occurs because backpropagation applies the chain rule across all layers, multiplying local gradients: ∂L/∂W₁ = (∂L/∂a₁₀) · (σ'(z₁₀)) · (W₁₀) · (σ'(z₉)) · (W₉) · ... · (σ'(z₁)). Then, sigmoid's derivative σ'(x) = σ(x)·(1-σ(x)) has maximum value 0.25 (at x=0). Even in the best case where all derivatives equal 0.25 and weights equal 1: gradient = 0.25^10 ≈ 9.5×10⁻⁷, which is essentially zero. Early-layer weights receive gradients so tiny they barely update during training, while later layers train normally—creating a bottleneck. In practice, neurons often saturate (σ'(x) ≈ 0), making the problem worse. This is why deep networks with sigmoid failed before ReLU: ReLU's derivative is 1.0 for positive inputs, preventing gradient shrinkage (0.25^10 becomes 1^10 = 1). Option B's misconception: chain rule doesn't preserve magnitude when multiplying small numbers. Option C's misconception: sigmoid derivative is always ≤ 0.25, never > 1. Option D's misconception: sigmoid derivatives are always positive; no sign flipping occurs. Finally, vanishing gradients fundamentally limit sigmoid's depth capacity.
Question 27 · PCA Variance · hard
In Principal Component Analysis (PCA), you compute the covariance matrix Σ = (1/n)XᵀX and its eigendecomposition. If eigenvalues are λ₁=100, λ₂=40, λ₃=20, λ₄=10, what percentage of total variance is explained by the first 2 principal components?
(100 + 40) / 100 = 1.40 or 140% because total variance is defined by the largest eigenvalue, not the sum of all eigenvalues
100 / (100 + 40 + 20 + 10) ≈ 58.8% because only the first principal component captures explained variance, not the first two combined
ExplanationFirst, PCA variance explained by first k components = (λ₁ + λ₂ + ... + λ_k) / Σλ_i. Total variance = 100 + 40 + 20 + 10 = 170. First 2 PCs: (100 + 40) / 170 = 140/170 ≈ 0.824 = 82.4%. This is why eigenvalues are sorted in descending order: the largest eigenvalues (and their corresponding eigenvectors) capture the most variance in the data. Retaining 82.4% of variance while using only 2 of 4 dimensions shows PCA's dimensionality reduction power.
Question 28 · Probability and Statistics · hard
Consider a dataset with 500 observations where P(Disease) = 0.02 and P(Positive Test|Disease) = 0.98, P(Positive Test|No Disease) = 0.05. Evaluate the actual probability of having the disease given a positive test result using Bayes theorem?
Approximately 0.98, because the test's 98% sensitivity is itself the probability of having the disease given a positive result
Approximately 0.02, because a positive test result does not change the prior probability of having the disease
The posterior probability is approximately 0.286 because P(Disease|Positive) = P(Positive|Disease) × P(Disease) / P(Positive) = 0.98 × 0.02 / (0.98 × 0.02 + 0.05 × 0.98) ≈ 0.286
Approximately 0.282, because the false-positive contribution is computed using P(Positive|No Disease) alone without multiplying by P(No Disease)
Answer: C. The posterior probability is approximately 0.286 because P(Disease|Positive) = P(Positive|Disease) × P(Disease) / P(Positive) = 0.98 × 0.02 / (0.98 × 0.02 + 0.05 × 0.98) ≈ 0.286
ExplanationBayes theorem states P(Disease|Positive) = P(Positive|Disease) × P(Disease) / P(Positive). Since P(Positive) = P(Positive|Disease) × P(Disease) + P(Positive|No Disease) × P(No Disease) = 0.98 × 0.02 + 0.05 × 0.98 = 0.0686, we calculate P(Disease|Positive) = (0.98 × 0.02) / 0.0686 ≈ 0.286. This demonstrates why even a highly sensitive test yields many false positives when screening for a rare disease: the low prior probability of 0.02 keeps the posterior probability well below the test's sensitivity, because the base rate significantly impacts posterior probability calculations.
Question 29 · Gradient Descent and Optimization · hard
A gradient descent update uses learning rate η = 0.1, current weight w = 3.0, and gradient ∂L/∂w = 4.0. What is the new weight value after one update step, and does this step move the weight toward the minimum of the loss function?
Subtracting the scaled gradient gives 2.6, since w_new = w - η × gradient = 3.0 - (0.1)(4.0) = 2.6, moving toward the minimum because the positive gradient signals that increasing w would increase the loss.
Adding the gradient step instead of subtracting yields 3.4, since w_new = w + η × gradient = 3.0 + (0.1)(4.0) = 3.4, which pushes the weight further in the direction the gradient points and away from the minimum.
Treating the scaled gradient itself as the new weight gives 0.4, equal to η × gradient = (0.1)(4.0) = 0.4, discarding the original weight value entirely in the update.
Misplacing the decimal in the learning rate produces 2.96, since w_new = w - η × gradient = 3.0 - 0.04 = 2.96, treating (0.1)(4.0) as 0.04 rather than 0.4.
Answer: A. Subtracting the scaled gradient gives 2.6, since w_new = w - η × gradient = 3.0 - (0.1)(4.0) = 2.6, moving toward the minimum because the positive gradient signals that increasing w would increase the loss.
ExplanationGradient descent updates the weight by moving opposite to the gradient direction: w_new = w − η × ∂L/∂w = 3.0 − (0.1)(4.0) = 3.0 − 0.4 = 2.6. Because the gradient is positive, the loss increases as w increases, so subtracting the scaled gradient decreases w and steps toward lower loss — that is, toward the minimum. Adding the gradient instead of subtracting it would push the weight in the wrong direction (away from the minimum); replacing the weight with just the scaled gradient discards the starting point entirely and is not how the update rule works; and shifting the decimal so that (0.1)(4.0) is read as 0.04 instead of 0.4 produces an arithmetic result that does not correspond to the stated learning rate of η = 0.1.
Question 30 · Linear Regression · hard
Analyze a linear regression model trained on 100 samples where the cost function J(θ) = (1/200) × Σ(hθ(xᵢ) - yᵢ)² achieved J(θ) = 2.5. Calculate the root mean squared error RMSE and evaluate what this value indicates about model fit?
RMSE cannot be calculated from the given cost function without knowing the individual residuals explicitly
RMSE = J(θ) = 2.5, meaning the average squared error directly equals the root mean squared error in linear regression
RMSE = √J(θ) = √2.5 ≈ 1.581, indicating excellent model fit with minimal prediction deviations
RMSE = √(2 × J(θ)) = √(2 × 2.5) = √5 ≈ 2.236, indicating moderate prediction error where typical predictions deviate 2.236 units from actual values
Answer: D. RMSE = √(2 × J(θ)) = √(2 × 2.5) = √5 ≈ 2.236, indicating moderate prediction error where typical predictions deviate 2.236 units from actual values
ExplanationFirst, since J(θ) = (1/200) × Σ(residuals)², multiplying by 200 gives Σ(residuals)² = 500. MSE = 500/100 = 5, therefore RMSE = √5 ≈ 2.236. Then, this value represents the standard deviation of prediction errors, showing typical predictions deviate by approximately 2.236 units. Understanding the relationship between cost function and RMSE is critical because different model formulations may normalize differently, requiring careful interpretation of absolute error magnitude.
Question 31 · Evaluation Metrics · hard
Given a confusion matrix for binary classification with TP = 48, FP = 12, TN = 85, FN = 5, calculate precision and recall then evaluate which metric better reflects model performance for detecting positive cases?
Both metrics equal approximately 0.85, making them equally useful for all classification problems regardless of context, since identical-looking scores mean the cost difference between false positives and false negatives can be ignored.
Precision and Recall both compute to 48/(48+12+5) ≈ 0.738 when treated as a single ratio of true positives over all misclassified cases combined, making precision equally suitable for judging how well positive cases are detected.
Precision = 48/(48+12) = 0.80 and Recall = 48/(48+5) = 0.906. Recall is better for this scenario because it measures the proportion of actual positive cases correctly identified, which is critical when missing positive cases has severe consequences
Recall = 0.80 and Precision = 0.906, where precision should always be prioritized in machine learning applications, but this reasoning fails because it overlooks the higher cost of missing true positive cases in this specific scenario.
Answer: C. Precision = 48/(48+12) = 0.80 and Recall = 48/(48+5) = 0.906. Recall is better for this scenario because it measures the proportion of actual positive cases correctly identified, which is critical when missing positive cases has severe consequences
ExplanationFirst, precision = TP/(TP+FP) = 48/60 = 0.80; Recall = TP/(TP+FN) = 48/53 ≈ 0.906. High recall (0.906) means the model catches most positive cases, while precision (0.80) indicates some false alarms. Then, for disease detection or security, missing positives is dangerous, therefore recall matters more. The tradeoff between precision-recall is fundamental: high precision reduces false alarms but misses cases, while high recall catches cases but produces false alarms.
Question 32 · Logistic Regression · hard
Evaluate a logistic regression model using sigmoid function σ(z) = 1/(1 + e^(-z)) where z = θ₀ + θ₁x. Given θ₀ = -3 and θ₁ = 0.5, predict the probability of class 1 when x = 7 and analyze the decision boundary?
When x = 7, the model predicts class 1 with certainty (probability = 1.0) since sigmoid outputs are always absolute
The probability equals 0.5 regardless of x value because the sigmoid function always approaches 0.5 as the standard prediction
When x = 7, z = -3 + 0.5(7) = 0.5, so σ(0.5) = 1/(1 + e^(-0.5)) ≈ 0.622. The decision boundary (σ = 0.5) occurs at z = 0, meaning -3 + 0.5x = 0 gives x = 6. For x > 6, the model predicts class 1 with increasing probability
The decision boundary cannot be determined from logistic regression parameters alone without additional data
Answer: C. When x = 7, z = -3 + 0.5(7) = 0.5, so σ(0.5) = 1/(1 + e^(-0.5)) ≈ 0.622. The decision boundary (σ = 0.5) occurs at z = 0, meaning -3 + 0.5x = 0 gives x = 6. For x > 6, the model predicts class 1 with increasing probability
ExplanationFirst, z = -3 + 0.5 × 7 = 0.5, therefore σ(0.5) = 1/(1 + e^(-0.5)) = 1/(1 + 0.6065) ≈ 0.622. The decision boundary where σ(z) = 0.5 occurs when z = 0 (since sigmoid(0) = 0.5), so -3 + 0.5x = 0 yields x = 6. Then, this linear decision boundary separates feature space: x < 6 predicts class 0, x > 6 predicts class 1. Understanding how logistic regression parameters determine probability and decision boundaries is essential for model interpretation.
Question 33 · Regularization · hard
Consider training a neural network using stochastic gradient descent with cross-entropy loss. The training loss decreases from epoch 1 (loss = 2.5) to epoch 50 (loss = 0.8) while validation loss plateaus at 1.8 after epoch 20. Analyze what this pattern indicates and evaluate appropriate regularization strategies?
This indicates overfitting because training loss continues decreasing (from 2.5 to 0.8) while validation loss stagnates at 1.8, showing the model memorizes training data but fails to generalize. Solutions include: L2 regularization (add λ∑θᵢ² to loss) to penalize large weights, dropout (randomly deactivate neurons), early stopping at epoch 20 when validation loss stopped improving, or data augmentation to increase effective training set size
The model is underfitting because validation loss (1.8) remains higher than training loss (0.8); the standard fix would be to increase model capacity — add more layers or parameters — until training loss approaches zero
No regularization is needed, since a continually decreasing training loss (from 2.5 down to 0.8) always signals successful learning regardless of validation performance, so training should simply continue past epoch 50
The persistent gap between training and validation loss most likely means the two sets come from different data distributions, so the priority is checking for data leakage or a flawed train/validation split, not applying regularization
Answer: A. This indicates overfitting because training loss continues decreasing (from 2.5 to 0.8) while validation loss stagnates at 1.8, showing the model memorizes training data but fails to generalize. Solutions include: L2 regularization (add λ∑θᵢ² to loss) to penalize large weights, dropout (randomly deactivate neurons), early stopping at epoch 20 when validation loss stopped improving, or data augmentation to increase effective training set size
ExplanationOverfitting occurs when training error keeps falling while validation error stagnates or rises, because the model starts memorizing training examples instead of learning patterns that generalize. Here, training loss drops steadily from 2.5 to 0.8 across 50 epochs, while validation loss stops improving and holds at 1.8 from epoch 20 onward — opening a persistent gap between the two curves, which is the defining signature of overfitting rather than underfitting (underfitting would show both losses staying high together, not diverging). Appropriate countermeasures include L2 regularization, which adds λ∑θᵢ² to the loss to penalize large weights; dropout, which randomly deactivates neurons during training to discourage over-reliance on specific feature combinations; early stopping around epoch 20, where validation loss last improved before plateauing; and data augmentation to expand the effective training set. This is why the observed pattern reflects overfitting requiring regularization, not underfitting, a distribution mismatch, or a case needing no intervention.
Question 34 · Evaluation Metrics · hard
A binary classifier for detecting a rare disease is evaluated at three probability thresholds, each producing a different precision-recall pair: at t=0.2, precision = 0.60 and recall = 0.95; at t=0.4, precision = 0.78 and recall = 0.85; at t=0.6, precision = 0.92 and recall = 0.60. Using the F1-score formula F1 = 2PR/(P+R) to measure the balance between precision and recall, which threshold gives the classifier its best overall balance between precision and recall?
Computing F1 = 2PR/(P+R) at each threshold shows t=0.4 has the highest score: t=0.2 gives F1 ≈ 0.735, t=0.4 gives F1 ≈ 0.813, and t=0.6 gives F1 ≈ 0.726, so t=0.4 delivers the best balance of precision and recall.
Selecting t=0.2 gives the best F1-score since its recall of 0.95 is the highest of the three thresholds, and F1-score is effectively determined by whichever of precision or recall is larger at a given threshold.
Choosing t=0.6 maximizes F1-score because its precision of 0.92 is the highest recorded value, and the harmonic mean formula always assigns the greatest weight to whichever single metric is largest.
Thresholds t=0.2 and t=0.6 tie for the highest F1-score because swapping precision and recall values between them (0.60/0.95 versus 0.92/0.60) produces mathematically identical harmonic means.
Answer: A. Computing F1 = 2PR/(P+R) at each threshold shows t=0.4 has the highest score: t=0.2 gives F1 ≈ 0.735, t=0.4 gives F1 ≈ 0.813, and t=0.6 gives F1 ≈ 0.726, so t=0.4 delivers the best balance of precision and recall.
ExplanationF1-score is the harmonic mean of precision and recall, F1 = 2PR/(P+R), which rewards balance between the two rather than being driven by whichever single value is larger. Computing each: at t=0.2, P=0.60 and R=0.95 give P+R=1.55 and PR=0.57, so F1 = 2(0.57)/1.55 ≈ 0.735. At t=0.4, P=0.78 and R=0.85 give P+R=1.63 and PR=0.663, so F1 = 2(0.663)/1.63 ≈ 0.813. At t=0.6, P=0.92 and R=0.60 give P+R=1.52 and PR=0.552, so F1 = 2(0.552)/1.52 ≈ 0.726. Comparing the three, t=0.4 produces the highest F1-score (≈0.813), meaning it strikes the best balance — even though t=0.2 has the single highest recall and t=0.6 has the single highest precision, neither has the highest F1, because the harmonic mean penalizes a low value on the other metric more heavily than a simple average would. This also shows why the tie claimed between t=0.2 and t=0.6 does not hold: true symmetry in the F1 formula requires the precision and recall values to actually swap places between two thresholds, but here the 0.95 at t=0.2 does not match the 0.92 at t=0.6, so their F1-scores (0.735 vs 0.726) come out slightly different rather than equal.
Question 35 · Cross-Validation · hard
A dataset for a spam classifier contains 100 emails: 90 labeled "Not Spam" and 10 labeled "Spam". A student runs standard (non-stratified) 5-fold cross-validation, where each fold is formed by randomly shuffling and splitting the data into 5 equal parts of 20 emails each. Why can this random splitting produce unreliable estimates of the classifier's spam-detection performance, and what does stratified k-fold cross-validation do to fix this?
Because only 10 'Spam' emails exist for random assignment across 5 folds, pure chance can leave some folds with far fewer than the expected 2 Spam emails (even zero) while others get more, so a fold's test-set recall on Spam swings wildly and a training fold starved of Spam examples produces a weaker classifier; stratified k-fold instead allocates exactly 2 Spam and 18 Not-Spam emails to every fold, preserving the dataset's 9:1 ratio in each split and giving consistent, comparable estimates across all 5 iterations.
Random splitting is unreliable here only because 100 emails divided by 5 folds leaves a remainder, so some folds inevitably contain 21 emails and others 19, an imbalance stratified k-fold corrects by discarding the extra emails so every fold holds exactly 20.
Stratified k-fold fixes the problem by duplicating existing Spam emails through oversampling until each of the 5 training folds contains an equal count of Spam and Not-Spam emails, effectively balancing the classes before every training run.
Since the total dataset size (100) is exactly divisible by the number of folds (5), every standard random split is mathematically guaranteed to place exactly 2 Spam emails in each fold, so stratification offers no additional benefit for this particular dataset.
Answer: A. Because only 10 'Spam' emails exist for random assignment across 5 folds, pure chance can leave some folds with far fewer than the expected 2 Spam emails (even zero) while others get more, so a fold's test-set recall on Spam swings wildly and a training fold starved of Spam examples produces a weaker classifier; stratified k-fold instead allocates exactly 2 Spam and 18 Not-Spam emails to every fold, preserving the dataset's 9:1 ratio in each split and giving consistent, comparable estimates across all 5 iterations.
ExplanationWith 10 Spam emails spread across 5 folds by pure random chance, the probability that any given fold ends up with 0, 1, 3, or more Spam emails instead of the expected 2 is substantial, since each fold only holds 20 emails and Spam make up just 10% of the pool. A fold whose test set happens to receive very few or zero Spam emails cannot meaningfully measure spam-detection recall for that iteration, and a fold whose training portion (the other 4 folds combined) happens to be short on Spam examples will train a weaker classifier for that iteration. Averaged over all 5 iterations, these chance imbalances inflate the variance of the reported metric and can bias the mean estimate. Stratified k-fold prevents this by sorting samples by class label first and then distributing them so each fold gets a proportional share: 10 Spam / 5 folds = 2 Spam per fold, and 90 Not-Spam / 5 folds = 18 Not-Spam per fold, so every fold and its corresponding training set preserves the same 9:1 class ratio as the full dataset. This is standard practice (e.g., scikit-learn's StratifiedKFold) whenever a dataset has imbalanced classes, because it removes random class-distribution noise as a source of estimate variance, leaving only genuine model-quality differences to be measured. Note also that 100 divides evenly by 5 with no remainder, so any claim resting on leftover emails or on divisibility guaranteeing balanced classes is factually mistaken — divisibility of the total says nothing about how the minority class happens to fall across folds.
Question 36 · Convolutional Neural Networks · hard
A convolutional layer receives a 32×32×3 input image and applies 16 filters of size 5×5, using stride 2 and padding 2 on each side. What are the output feature map's spatial dimensions and the total number of trainable parameters in this layer?
Computing floor((32 − 5 + 2·2)/2) + 1 yields a 16×16 spatial output, and since each filter has 5×5×3 = 75 weights plus one bias, the total parameter count is 16 × 76 = 1216.
Using the same output-size formula, floor((32 − 5 + 2·2)/2) + 1, still gives 16×16, yet the parameter total is only 1200, because each filter's bias term is mistakenly omitted from the 5×5×3 weight count.
Dropping the padding term from the size formula produces a 14×14 output, computed as floor((32 − 5)/2) + 1 = 14, though the parameter count still correctly totals 1216.
Assuming each filter connects to only one input channel rather than all three gives a parameter total of 416, computed as 16 × (25 + 1) = 416, while the output remains 16×16.
Answer: A. Computing floor((32 − 5 + 2·2)/2) + 1 yields a 16×16 spatial output, and since each filter has 5×5×3 = 75 weights plus one bias, the total parameter count is 16 × 76 = 1216.
ExplanationUsing the standard convolution output-size formula, output = floor((W − F + 2P)/S) + 1, with W=32, F=5, P=2, S=2: (32 − 5 + 4)/2 + 1 = 31/2 + 1 = 15.5, which floors to 15, then +1 gives 16. So the output feature map is 16×16 with 16 channels, one per filter. For parameters, each filter must span the full input depth of 3 channels, not just its 5×5 footprint, so each filter has 5×5×3 = 75 weights plus 1 bias term, giving 76 parameters per filter. With 16 filters, the total is 16 × 76 = 1216 trainable parameters. Three common errors produce the wrong numbers seen in the distractors: dropping the padding term from the size formula gives an incorrect 14×14 output; forgetting each filter's bias term undercounts the total to 1200; and forgetting that a filter spans every input channel (treating it as if it only sees one channel) undercounts the total to 416.
Question 37 · Computer Science · hard
An XGBoost regression tree is being built, and a candidate leaf accumulates gradient statistic G = -12 and Hessian statistic H = 4 from the training examples routed into it. The optimal leaf weight under L2 regularization strength λ is w* = -G / (H + λ). If the model is retrained with λ = 8 instead of λ = 2, what happens to the optimal leaf weight and the model's tendency to overfit?
Because the optimal weight follows w* = -λ·G/H when regularization scales the gradient term, the weight grows from w*=6.0 at λ=2 to w*=24.0 at λ=8, so higher λ actually makes the model fit training data more aggressively.
Since the denominator of the optimal-weight formula is λ alone, the weight shrinks from w*=6.0 at λ=2 to w*=1.5 at λ=8, meaning the Hessian statistic H has no bearing on the result once regularization is applied.
Both settings produce the identical optimal weight w*=2.0, because λ only rescales the overall loss during boosting rounds and does not change how individual leaf weights are computed.
Using w* = -G/(H+λ), the optimal weight shrinks from w*=2.0 at λ=2 to w*=1.0 at λ=8, so larger λ pulls leaf weights toward zero and reduces overfitting.
Answer: D. Using w* = -G/(H+λ), the optimal weight shrinks from w*=2.0 at λ=2 to w*=1.0 at λ=8, so larger λ pulls leaf weights toward zero and reduces overfitting.
ExplanationThe optimal leaf weight formula is w* = -G/(H+λ), derived by minimizing the second-order Taylor approximation of the loss plus the L2 penalty λw². With G=-12 and H=4: at λ=2, w* = -(-12)/(4+2) = 12/6 = 2.0; at λ=8, w* = -(-12)/(4+8) = 12/12 = 1.0. Raising λ from 2 to 8 enlarges the denominator, so the weight is pulled closer to zero — the leaf makes a smaller, more conservative prediction. Smaller leaf weights mean the tree relies less on any single split to fit the training data exactly, which is precisely how L2 regularization curbs overfitting: it trades a small amount of training-set fit for a model that generalizes better to unseen data.
Question 38 · Cross-Validation · hard
Leave-One-Out Cross-Validation (LOOCV) trains on n-1 samples and tests on 1 sample, repeating n times. For n=1000, this requires 1000 model trainings, compared to just 5 model trainings for 5-fold cross-validation. Considering the resulting difference in computational cost as well as the bias-variance tradeoff between the two approaches, when should you use LOOCV despite its computational cost?
LOOCV and k-fold have identical computational cost
LOOCV requires 1000 trainings (vs 5 for 5-fold), making it 200× more expensive. LOOCV variance ≈ 5× higher than 5-fold because each test set has only 1 sample (very noisy). Bias-variance: LOOCV lower bias (99.9% training) vs 5-fold higher bias (80% training), but variance dominates. Use LOOCV only for small n (<100) where computational cost is acceptable and variance matters more than bias.
LOOCV has lower variance than k-fold
Since LOOCV trains on nearly the entire dataset each time, it always produces a less biased and more computationally efficient estimate than 5-fold CV, making it the preferred choice for any dataset size.
Answer: B. LOOCV requires 1000 trainings (vs 5 for 5-fold), making it 200× more expensive. LOOCV variance ≈ 5× higher than 5-fold because each test set has only 1 sample (very noisy). Bias-variance: LOOCV lower bias (99.9% training) vs 5-fold higher bias (80% training), but variance dominates. Use LOOCV only for small n (<100) where computational cost is acceptable and variance matters more than bias.
ExplanationFirst, LOOCV trains model 1000 times (on n-1 = 999 samples each), testing on held-out sample. 5-fold trains 5 times (on 400 samples each), testing on 100 samples. Then, LOOCV cost = 1000 / 5 = 200× higher. Variance: LOOCV test error is computed from 1000 single-sample errors ŷ_i - y_i. If sample i is an outlier, ŷ_i - y_i is extreme, inflating variance. Averaging 1000 high-variance estimates yields high-variance mean. 5-fold averages 5 estimates, each computed from 100-sample test sets, reducing variance. Thus Var[LOOCV] / Var[5-fold] ≈ 5. LOOCV bias: training on 999 samples almost matches full-sample bias (low bias). 5-fold trains on fewer samples per fold, introducing bias from the missing held-out portion. Use LOOCV only for n ≤ 100 (computational cost ≤ 100 trainings acceptable) where bias matters more than variance, or for very noisy small data where every sample's prediction is precious. For n=1000, LOOCV is prohibitive; use nested 5-fold CV instead (outer for hyperparameter selection, inner for validation).
Question 39 · Cross-Validation · hard
You perform 5-fold cross-validation on 500 samples to select hyperparameter λ (regularization strength). Folds use splits: Fold 1 (80 train, 20 test), Fold 2–5 identical. For each fold, you evaluate logistic regression with λ ∈ {0.001, 0.01, 0.1, 1.0}. Results show: λ=0.001 has CV accuracies [0.95, 0.85, 0.95, 0.85, 0.90] → mean=0.90, std≈0.05; λ=0.1 has CV accuracies [0.89, 0.88, 0.90, 0.89, 0.89] → mean=0.89, std≈0.007. Explain which λ you would select and why, referencing the bias-variance tradeoff, the standard error of each mean, and the one-standard-error rule?
λ=0.001 should be selected because it has the higher mean accuracy (0.90 vs 0.89); once a cross-validation mean is computed, fold-to-fold variance provides no additional information about how well the model will generalize to unseen data.
λ=0.1 should be selected because its cross-validation accuracy is far more stable across folds (std ≈ 0.007 vs 0.05) and its mean of 0.89 lies within one standard error of λ=0.001's mean (SE ≈ 0.0224, so 0.90 − SE ≈ 0.878 < 0.89); by the one-standard-error rule, the more heavily regularized model is preferred when its performance is statistically indistinguishable from the best while being less sensitive to which samples land in each fold.
Both λ values are equivalent because their 95% confidence intervals overlap; whenever two candidates' confidence intervals overlap, cross-validation results give no principled basis for preferring one hyperparameter over the other.
λ=0.1 should be rejected in favor of λ=0.001 because with only 20 held-out samples per fold, cross-validation standard errors are too imprecise to ever justify choosing a lower mean-accuracy model, no matter how consistent its fold results are.
Answer: B. λ=0.1 should be selected because its cross-validation accuracy is far more stable across folds (std ≈ 0.007 vs 0.05) and its mean of 0.89 lies within one standard error of λ=0.001's mean (SE ≈ 0.0224, so 0.90 − SE ≈ 0.878 < 0.89); by the one-standard-error rule, the more heavily regularized model is preferred when its performance is statistically indistinguishable from the best while being less sensitive to which samples land in each fold.
ExplanationFor λ=0.001, mean accuracy across the 5 folds is 0.90 with sample standard deviation ≈0.05 (fold results swing widely, from 0.85 to 0.95). Standard error SE = 0.05/√5 ≈ 0.0224, giving a 95% CI of 0.90 ± 1.96×0.0224 ≈ [0.856, 0.944]. For λ=0.1, mean accuracy is 0.89 with sample standard deviation ≈0.007 (folds stay tightly between 0.88 and 0.90), so SE = 0.0071/√5 ≈ 0.0032, giving a 95% CI of 0.89 ± 1.96×0.0032 ≈ [0.884, 0.896]. λ=0.1's entire CI sits inside λ=0.001's much wider CI, so the 0.01 mean-accuracy gap is not statistically significant — it is well under one SE of λ=0.001, let alone the 2×SE threshold typically used to call a difference significant. Applying the one-standard-error rule: among models whose mean CV accuracy is within one SE of the best observed mean, the convention is to pick the most heavily regularized (simplest) one, since it is likely to generalize just as well while being less sensitive to the particular data split. Here 0.90 − 1×SE(λ=0.001) ≈ 0.90 − 0.0224 ≈ 0.878, and λ=0.1's mean of 0.89 clears that bar, so it qualifies. This lines up with the bias-variance tradeoff (Test Error ≈ Bias² + Variance + Noise): λ=0.001 has lower bias but its accuracy varies by 10 points across folds, a hallmark of high variance — it is partly fitting noise specific to each fold's split rather than a stable decision boundary. λ=0.1 has slightly higher bias but only a 2-point spread across folds, showing it captures a signal that holds up consistently regardless of which samples land in training versus test. Since the two means are not statistically distinguishable, this stability is the deciding factor, so λ=0.1 is the better choice.
Question 40 · ROC-AUC · hard
A hospital deploys a binary classifier to flag patients at high risk for a rare disease, validated on 10,000 patients: 200 have the disease (positive class) and 9,800 do not (negative class). At decision threshold 0.5, the model achieves TPR = 0.70 and FPR = 0.04. Lowering the threshold to 0.2 raises TPR to 0.95 but also raises FPR to 0.15. If a missed disease case (false negative) costs the hospital 20 times as much as an unnecessary follow-up test triggered by a false alarm (false positive), which threshold produces the lower total expected cost, and by how much?
Threshold 0.5 minimizes total expected cost at 1,592 units (60 false negatives weighted at 20 plus 392 false positives) versus 1,670 units at threshold 0.2, because the 9,800 healthy patients turn a 0.15 FPR into far more added false alarms than the extra 50 true positives save.
Lowering the threshold to 0.2 always minimizes total cost here, since a false-negative penalty 20 times larger than a false-positive penalty guarantees that maximizing recall outweighs any rise in false alarms.
Neither operating point can be compared on total cost, because ROC-AUC summarizes performance independent of threshold, making every confusion matrix on the curve equally optimal for deployment.
Threshold 0.2 minimizes total expected cost at 1,670 units against 1,592 units for threshold 0.5, so accepting 10 false negatives instead of 60 justifies nearly four times as many false positives.
Answer: A. Threshold 0.5 minimizes total expected cost at 1,592 units (60 false negatives weighted at 20 plus 392 false positives) versus 1,670 units at threshold 0.2, because the 9,800 healthy patients turn a 0.15 FPR into far more added false alarms than the extra 50 true positives save.
ExplanationAt threshold 0.5, TPR 0.70 on 200 positive patients gives 140 true positives and 60 false negatives, while FPR 0.04 on 9,800 negative patients gives 392 false positives. Weighting each false negative at 20 cost units and each false positive at 1 unit gives a total cost of (60 × 20) + 392 = 1,592 units. At threshold 0.2, TPR 0.95 gives 190 true positives and only 10 false negatives, but FPR 0.15 on the same 9,800 negatives gives 1,470 false positives, for a total cost of (10 × 20) + 1,470 = 1,670 units. Even though threshold 0.2 saves 50 additional true positives and cuts false negatives by 50 at a 20x penalty, the massive negative class turns its higher FPR into 1,078 more false positives than threshold 0.5 produces — more than enough to erase the savings. Threshold 0.5 therefore has the lower total cost, by 78 units. This shows why comparing thresholds by rates alone (TPR, FPR) can mislead on imbalanced data: rates must be converted to actual counts using the class base rates before applying cost weights, and ROC-AUC itself, being threshold-independent, cannot answer a question about cost at a specific operating point.