Question 41 · Linear Regression & Gradient Descent · hard
A machine learning model is trained on two raw features: weekly study hours X₁, uniformly distributed over [2, 6] hours (range = 4), and monthly family income X₂, uniformly distributed over ₹10,000–₹130,000, expressed in ₹-thousands as [10, 130] (range = 120). Assuming each feature's variance can be approximated as σ² = (range)²/12, and treating the covariance matrix as diagonal so that κ = λ_max/λ_min equals the ratio of the largest to smallest feature variance, the model applies z-score standardization X_norm = (X − μ)/σ to both features before running gradient descent. What is the condition number of the covariance matrix after standardization, and by what factor was the pre-standardization condition number larger?
Standardization drives κ down to exactly 1 because every feature's variance becomes 1; since κ was 900 before scaling (1200 divided by 4/3), gradient descent converges roughly 900× faster with circular, evenly-scaled loss contours.
The condition number only falls to about 12 after scaling, since bounding each feature between 0 and 1 leaves residual variance of 1/12 rather than a full unit, so some anisotropy in the loss surface survives.
Centering and scaling never touch κ at all — subtracting the mean merely repositions the data, so the condition number stays fixed at its pre-scaling value of 900 regardless of standardization.
Using the ranges directly gives a condition number of 30 before scaling (120 divided by 4), which standardization then reduces to 1, a thirtyfold speedup in convergence.
Answer: A. Standardization drives κ down to exactly 1 because every feature's variance becomes 1; since κ was 900 before scaling (1200 divided by 4/3), gradient descent converges roughly 900× faster with circular, evenly-scaled loss contours.
ExplanationFor a diagonal covariance matrix, each eigenvalue equals a feature's variance, so κ = λ_max/λ_min is just the ratio of the largest to smallest feature variance. Treating each feature as uniformly distributed over its stated range, variance ≈ (range)²/12: for study hours (range = 4), σ₁² = 16/12 = 4/3 ≈ 1.33; for family income in ₹-thousands (range = 120), σ₂² = 14400/12 = 1200. That gives κ_before = 1200 ÷ (4/3) = 900. Z-score standardization replaces each feature with (X − μ)/σ, and by construction the standardized variable has variance σ²/σ² = 1 for every feature — not 1/12, which would instead describe a feature min-max-rescaled into [0,1], a different technique from the one applied here. So after standardization λ_max = λ_min = 1, giving κ_after = 1, a 900-fold drop from the original value. Note that the condition number scales with the square of the range ratio (120/4 = 30, and 30² = 900), not with the raw range ratio itself — using 30 directly skips the squaring step built into the variance formula. Since gradient descent's convergence rate depends on κ (near-circular contours when κ is close to 1, narrow elongated valleys when κ is large), this 900-fold reduction translates into far fewer iterations needed to reach the minimum, with standardized features contributing comparably sized gradients along every direction.
Question 42 · Linear Regression & Gradient Descent · hard
Implement ridge regression with regularization term λ*||w||^2 in the cost function: J(w) = 1/(2m)*||Xw-y||^2 + (λ/(2m))*||w||^2, where X is 200×10, λ=0.1, and the analytical solution is w = (X^T*X + λ*I)^(-1)*X^T*y. How does increasing λ from 0.1 to 10 affect the weight magnitudes and the rank of the matrix (X^T*X + λ*I)?
Weight magnitudes shrink monotonically in every direction as λ rises from 0.1 to 10 (each eigen-direction scales by σ_i/(σ_i+λ), a ratio that strictly decreases with λ), while the rank of (X^T*X + λ*I) stays exactly 10, because λ*I shifts every eigenvalue of X^T*X up to a strictly positive value, guaranteeing invertibility regardless of λ's size
Larger λ makes every weight component grow, since amplifying the regularization coefficient increases the penalty term's contribution to the gradient and pushes ||w||^2 upward, while the rank of (X^T*X + λ*I) drops to 9 because one eigen-direction becomes linearly dependent once λ exceeds its corresponding eigenvalue
Ridge regularization leaves weight magnitudes completely unchanged for any λ, because (X^T*X + λ*I)^(-1)*X^T*y algebraically reduces back to the ordinary least-squares estimate (X^T*X)^(-1)*X^T*y once the inverse is expanded, while the rank of (X^T*X + λ*I) rises to 11 because adding λ*I introduces an extra row and column to the parameter space
Raising λ from 0.1 to 10 collapses the rank of (X^T*X + λ*I) from 10 to 0, because once λ exceeds 1 the identity term numerically dominates every entry and forces all ten eigenvalues to zero, while weight magnitudes remain completely unchanged since only the matrix being inverted is modified, not the target vector y
Answer: A. Weight magnitudes shrink monotonically in every direction as λ rises from 0.1 to 10 (each eigen-direction scales by σ_i/(σ_i+λ), a ratio that strictly decreases with λ), while the rank of (X^T*X + λ*I) stays exactly 10, because λ*I shifts every eigenvalue of X^T*X up to a strictly positive value, guaranteeing invertibility regardless of λ's size
ExplanationStep-by-step derivation from the ridge closed form w = (X^T*X + λ*I)^(-1)*X^T*y: (1) Write the eigendecomposition X^T*X = U*Σ*U^T, where Σ = diag(σ_1,...,σ_10) holds the 10 (non-negative) eigenvalues of the 10×10 matrix X^T*X. (2) Then X^T*X + λ*I = U*(Σ + λ*I)*U^T, so the eigenvalues of the regularized matrix are exactly σ_i + λ, one per direction. (3) Since σ_i ≥ 0 and λ > 0, every σ_i + λ is strictly positive — even a direction where X is rank-deficient (σ_i = 0) becomes invertible once λ*I is added. This holds equally at λ=0.1 and λ=10, so the rank of (X^T*X + λ*I) stays exactly 10 across the whole increase; λ never drives it toward 9, 0, or above 10. (4) For the weight magnitudes, rotate into the eigenbasis: with w̃ = U^T*w, each component of the ridge solution is w̃_i = c_i/(σ_i + λ) for some data-dependent constant c_i, while the unregularized (λ→0) value in that same direction would be c_i/σ_i. So each component shrinks by the ratio σ_i/(σ_i + λ) relative to the unregularized solution, and this ratio is strictly decreasing in λ (its derivative is −σ_i/(σ_i + λ)^2 < 0). Raising λ from 0.1 to 10 therefore shrinks every one of the 10 weight components further, though the exact amount differs per direction and depends on the specific singular values of this X — no fixed global percentage can be claimed without knowing them. Weights do not grow, do not stay identical, and the rank does not move away from 10; those are the concrete errors in the other three answers.
Question 43 · Decision Trees & Random Forests · hard
A decision tree classifier is trained on a dataset of exactly 40 samples, with the hyperparameters max_depth = 4 and min_samples_leaf = 5 (every leaf must contain at least 5 samples). The tree is allowed to grow as far as these two constraints permit. What is the maximum possible number of leaf nodes in the resulting tree?
Sixteen leaf nodes is the maximum, because max_depth = 4 alone permits up to 2^4 leaves in a full binary tree, and min_samples_leaf only restricts individual splits rather than lowering this depth-based ceiling.
Eight leaf nodes is the true maximum, since distributing 40 samples into leaves holding at least 5 samples each allows at most ⌊40/5⌋ = 8 leaves, a limit that is reachable well within depth 4, making the sample-count constraint the binding one rather than the depth constraint.
Five leaf nodes is the maximum, because min_samples_leaf = 5 fixes the total leaf count directly, regardless of how many samples are available or how deep the tree is allowed to grow.
Four leaf nodes is the maximum, because max_depth = 4 means the tree can branch exactly four times overall, yielding one leaf for every unit of depth.
Answer: B. Eight leaf nodes is the true maximum, since distributing 40 samples into leaves holding at least 5 samples each allows at most ⌊40/5⌋ = 8 leaves, a limit that is reachable well within depth 4, making the sample-count constraint the binding one rather than the depth constraint.
ExplanationTwo independent limits cap the number of leaves here, and the smaller one wins. The depth limit alone would allow up to 2^4 = 16 leaves in a full binary tree of depth 4. But min_samples_leaf = 5 means every leaf must hold at least 5 of the 40 training samples, so the dataset can support at most ⌊40/5⌋ = 8 leaves — a ninth leaf would push the total requirement to 9 × 5 = 45 samples, more than the 40 available. Because 8 is smaller than 16, the sample-count limit is the one that actually binds, not the depth limit. This 8-leaf split is also reachable without violating max_depth: split 40 into two groups of 20, then each 20 into two groups of 10, then each 10 into two groups of 5 — three splits deep, comfortably inside the depth-4 allowance, ending in 8 leaves of exactly 5 samples each. Treating min_samples_leaf as if it directly fixes the leaf count, or treating max_depth as if it produces one leaf per unit of depth, both ignore how the two hyperparameters actually interact: max_depth bounds how many times the tree can branch, while min_samples_leaf bounds how finely the data itself can be subdivided, and the tighter of the two determines the achievable maximum.
Question 44 · SVM & Kernel Methods · hard
Implement kernel SVM with polynomial kernel K(x_i, x_j) = (1 + x_i^T*x_j)^p where p=3, and compute the explicit feature space dimension d_explicit = C(d_implicit + p - 1, p). For d_implicit = 10 features and p=3, calculate d_explicit and explain how this affects training complexity and generalization in terms of the curse of dimensionality?
Polynomial kernel (1 + x_i^T*x_j)^3 implicitly maps 10D input to d_explicit = C(10+3-1,3) = C(12,3) = 220D feature space, increasing training time from O(m²*d) to O(m²*220) ≈ O(m²), but improving generalization because the 220D space separates nonlinear patterns with large margin, reducing test error when classes form polynomial boundaries
Polynomial kernel reduces feature dimensionality to 3 regardless of input dimension, which would completely change the algorithm's behavior and produce a fundamentally different result from what is expected
Explicit feature space dimension equals polynomial degree p=3, making computation faster than implicit kernel trick, but this misunderstanding arises from confusing the theoretical worst-case with the actual average-case execution path
Higher-degree polynomials always reduce overfitting because larger feature spaces have more capacity — however this contradicts the established mathematical properties that govern this computation's correctness guarantees
Answer: A. Polynomial kernel (1 + x_i^T*x_j)^3 implicitly maps 10D input to d_explicit = C(10+3-1,3) = C(12,3) = 220D feature space, increasing training time from O(m²*d) to O(m²*220) ≈ O(m²), but improving generalization because the 220D space separates nonlinear patterns with large margin, reducing test error when classes form polynomial boundaries
ExplanationStep-by-step: (1) Polynomial kernel (1 + x_i^T*x_j)^p creates monomial features of degree ≤p. (2) For d_implicit=10, p=3, the monomial features are: 1, x_i, x_i*x_j (all pairs), x_i*x_j*x_k (all triples). (3) Count: degree 0 = C(10,0)=1, degree 1 = C(10,1)=10, degree 2 = C(11,2)=55, degree 3 = C(12,3)=220. (4) Total: 1 + 10 + 55 + 220 = 286. Wait, using combinatorial formula: d_explicit = C(d_implicit+p, p) = C(13, 3) = 286. Actually, the standard formula is C(d+p, p) = C(13,3) = 286. Let me recalculate: C(12,3) = 12!/(3!*9!) = (12*11*10)/(3*2*1) = 1320/6 = 220. (5) So d_explicit ≈ 220 features. (6) Training complexity with kernel trick: O(m²) for Gram matrix (no explicit features needed). Without kernel trick: O(m*d_explicit*iterations) = O(m*220*iterations). (7) Generalization: 220D space with margin maximization typically reduces error from ~20% (linear SVM in 10D) to ~8-10% when true decision boundary is polynomial. (8) But curse of dimensionality: VC dimension grows as O(d²), so test error can increase if margin decreases. With proper regularization C, margin remains ~1/√C. Therefore, polynomial kernel trades off training time (mitigated by kernel trick O(m²)) for better fit to nonlinear patterns. Because the 220D space contains cross-terms (x_i*x_j) that capture interaction effects, the model can learn nonlinear decision boundaries while maintaining O(m²) computation via the kernel trick. This means polynomial SVM typically has 5-10% lower error than linear SVM on real datasets with no increase in wall-clock time.
Question 45 · feature scaling effect · hard
A dataset used for a linear regression model has two features: Age (typical range 18-60) and Annual Income in rupees, which has mean ₹150,000 and standard deviation ₹100,000 across the training set. Training with batch gradient descent and a single shared learning rate on the raw (unscaled) features requires about 10,000 epochs to converge to a given tolerance, because the loss surface is a highly elongated ellipse — the Income axis dominates the gradient and each step overshoots along that direction while barely moving along the Age axis. After applying StandardScaler (z = (x − mean) / std) to both features, the same tolerance is reached in about 10 epochs. Given a training example with Income = ₹250,000, what is the precise effect of this standardization on convergence behavior and on that data point's scaled Income value?
Standardizing the income feature shifts what the regression line actually predicts, so the fitted relationship between income and the target genuinely changes once the raw ₹250,000 value is replaced by its scaled version.
Standardizing makes the loss surface's contours closer to circular rather than a stretched ellipse, so a single shared learning rate can move almost directly toward the minimum instead of zig-zagging across the Income axis; concretely, the ₹250,000 income value becomes z = (250,000 − 150,000) / 100,000 = 1.0 under this scaler.
Because gradient descent uses one shared learning rate for every weight, training on the unscaled features would never reach the minimum at all, so reporting convergence after 10,000 epochs on raw data must be describing a different, better-conditioned dataset.
Feature scaling only changes convergence speed for algorithms like decision trees that split on raw feature values, while gradient descent is mathematically guaranteed to take the same number of steps to the minimum regardless of how differently the Age and Income axes are scaled.
Answer: B. Standardizing makes the loss surface's contours closer to circular rather than a stretched ellipse, so a single shared learning rate can move almost directly toward the minimum instead of zig-zagging across the Income axis; concretely, the ₹250,000 income value becomes z = (250,000 − 150,000) / 100,000 = 1.0 under this scaler.
ExplanationStandardizing does not change the model's optimal predictions in the original units — it only reshapes the optimization landscape it navigates. Before scaling, Income's raw values (mean ₹150,000, spread ₹100,000) are three orders of magnitude larger than Age's raw values, so the loss function's contour lines form a long, narrow ellipse stretched along the Income axis. A shared learning rate small enough to stay stable along the steep Income direction is far too small to make meaningful progress along the shallow Age direction, so gradient descent creeps toward the minimum in tiny, zig-zagging steps — this is why it takes about 10,000 epochs. StandardScaler removes this imbalance: subtracting the mean and dividing by the standard deviation puts every feature on a comparable scale (mean 0, standard deviation 1), so the contours become close to circular and a single learning rate can move nearly straight toward the minimum, cutting convergence to about 10 epochs. For the given data point, Income = ₹250,000 is (250,000 − 150,000) / 100,000 = 1.0 standard deviation above the mean, so its scaled value is z = 1.0. The claim that scaling changes what the model actually predicts is incorrect: once the learned weights are converted back to the original units, the fitted relationship is, up to numerical precision, the same function — scaling changes the path taken to find it, not the destination. The claim that unscaled training never converges is also wrong: the scenario states it does converge, just 1,000 times slower, and slow oscillating progress is not the same as no progress. Finally, decision trees split on the relative order of feature values, making them the algorithms least affected by feature scaling — gradient-based methods like this one are the ones scaling helps most, so the claim reverses which algorithm actually benefits.
Question 46 · Linear Regression · hard
You train a linear regression model y = wx + b on 4 data points: (1,3), (2,5), (3,7), (4,9). After training converges, what are the optimal values of w and b, and what would the model predict for x=10?
w=2, b=1, prediction=21 — the data follows y=2x+1 perfectly, so 2(10)+1=21
w=1.5, b=2.5, prediction=17.5 — least squares minimizes to these values
w=2, b=0, prediction=20 — the intercept is zero because the line passes through the origin
w=3, b=0, prediction=30 — the slope is the average y-value divided by average x-value
Answer: A. w=2, b=1, prediction=21 — the data follows y=2x+1 perfectly, so 2(10)+1=21
ExplanationCheck the pattern: (1,3): 2(1)+1=3. (2,5): 2(2)+1=5. (3,7): 2(3)+1=7. (4,9): 2(4)+1=9. All 4 points lie exactly on y=2x+1. Since the residuals are all zero, the least-squares solution is exactly w=2, b=1 with MSE=0. For x=10: y=2(10)+1=21. The key insight: when data is perfectly linear, regression recovers the exact generating function.
Question 47 · Classification Metrics · hard
You compute the confusion matrix for a binary classifier on 100 test samples: TP=40, FP=10, FN=20, TN=30. What is the F1 score?
0.727 — F1 = 2*precision*recall/(precision+recall) = 2*(0.8)*(0.667)/(0.8+0.667) = 0.727
Answer: A. 0.727 — F1 = 2*precision*recall/(precision+recall) = 2*(0.8)*(0.667)/(0.8+0.667) = 0.727
ExplanationPrecision = TP/(TP+FP) = 40/(40+10) = 40/50 = 0.8. Recall = TP/(TP+FN) = 40/(40+20) = 40/60 = 0.667. F1 = 2 * (0.8 * 0.667) / (0.8 + 0.667) = 2 * 0.5333 / 1.467 = 1.0667 / 1.467 = 0.727. Note that accuracy = (TP+TN)/total = 70/100 = 0.70, which is different from F1. F1 is the harmonic mean of precision and recall, giving equal weight to both. It is always between precision and recall: 0.667 < 0.727 < 0.8.
Question 48 · Gradient Descent · hard
You perform one step of gradient descent on the function f(x) = x^2 - 4x + 5 starting at x=0 with learning rate alpha=0.1. What is the new value of x after one step?
x = 0.4 — gradient f'(x) = 2x-4, at x=0: f'(0)=-4, new x = 0 - 0.1*(-4) = 0.4
x = -0.4 — new x = 0 - 0.1*(4) = -0.4, moving in the direction of the gradient
x = 0.5 — the minimum is at x=2, so gradient descent moves halfway in one step
x = 2.0 — gradient descent converges to the minimum in one step with any learning rate
Answer: A. x = 0.4 — gradient f'(x) = 2x-4, at x=0: f'(0)=-4, new x = 0 - 0.1*(-4) = 0.4
Explanationf(x) = x^2 - 4x + 5. The gradient (derivative) is f'(x) = 2x - 4. At x=0: f'(0) = 2(0) - 4 = -4. Gradient descent update: x_new = x_old - alpha * f'(x_old) = 0 - 0.1 * (-4) = 0 + 0.4 = 0.4. The negative gradient points toward the minimum (at x=2, where f'(x)=0). With learning rate 0.1, we take a small step from 0 toward 2, landing at 0.4. After many iterations, x would converge to 2.0, but one step only moves us to 0.4.
Question 49 · Data Preprocessing · hard
You normalize a feature vector [10, 20, 30, 40, 50] using min-max scaling to the range [0, 1]. What are the normalized values?
[0.2, 0.4, 0.6, 0.8, 1.0] — each value divided by the maximum (50)
[0.1, 0.2, 0.3, 0.4, 0.5] — each value divided by 100
[-1.0, -0.5, 0.0, 0.5, 1.0] — this is z-score normalization centered at 30
Answer: A. [0.0, 0.25, 0.5, 0.75, 1.0] — formula: (x - min)/(max - min) with min=10, max=50
ExplanationMin-max scaling formula: x_scaled = (x - x_min) / (x_max - x_min). Here x_min=10, x_max=50, so the range is 50-10=40. Apply to each: (10-10)/40 = 0/40 = 0.0. (20-10)/40 = 10/40 = 0.25. (30-10)/40 = 20/40 = 0.5. (40-10)/40 = 30/40 = 0.75. (50-10)/40 = 40/40 = 1.0. Result: [0.0, 0.25, 0.5, 0.75, 1.0]. This guarantees the minimum maps to 0 and maximum maps to 1. Dividing by max alone (option B) is a different scaling that doesn't guarantee 0 as minimum.
Question 50 · Matrix Operations · hard
You multiply two matrices using the @ operator in NumPy: A has shape (3x4) and B has shape (4x2). Given that C = A @ B, calculate the output shape of C and what is the total number of individual scalar multiplications performed during this matrix multiplication?
Shape 3x2, with 24 multiplications — each of the 6 output elements requires a dot product of length 4
Shape 4x4, with 16 multiplications — the inner dimensions create a square matrix
Shape 3x2, with 8 multiplications — only the diagonal elements require computation
Shape 3x4x2, with 24 multiplications — matrix multiply produces a 3D tensor
Answer: A. Shape 3x2, with 24 multiplications — each of the 6 output elements requires a dot product of length 4
ExplanationMatrix multiplication: (3x4) @ (4x2) → (3x2). The inner dimensions (4 and 4) must match (they do), and the output shape is (outer dimensions) = 3x2 = 6 elements. Each output element C[i,j] is the dot product of row i of A (length 4) with column j of B (length 4), requiring 4 multiplications and 3 additions. Total multiplications: 6 elements * 4 multiplications each = 24. Total additions: 6 * 3 = 18. This produces the count because each output element is a dot product of length n=4, requiring 4 multiplications. In general, multiplying (m x n) by (n x p) requires m*n*p multiplications.
Question 51 · Softmax and Classification · hard
You apply softmax to the logits vector [2.0, 1.0, 0.1]. Using e^2.0=7.389, e^1.0=2.718, e^0.1=1.105, what is the probability assigned to the first class?
ExplanationSoftmax formula: softmax(z_i) = e^z_i / sum(e^z_j). Sum of exponentials: e^2.0 + e^1.0 + e^0.1 = 7.389 + 2.718 + 1.105 = 11.212. P(class 0) = 7.389 / 11.212 = 0.659 (65.9%). P(class 1) = 2.718 / 11.212 = 0.242 (24.2%). P(class 2) = 1.105 / 11.212 = 0.099 (9.9%). Sum = 1.000. The softmax function converts raw logits to a valid probability distribution. Higher logits get exponentially more probability — the gap between 2.0 and 1.0 in logit space becomes 7.389 vs 2.718 (2.7x ratio) in probability space.
Question 52 · K-Nearest Neighbors · hard
You train a k-NN classifier with k=3 on the following 2D points: Class A: (1,1), (2,2), (1,3). Class B: (5,5), (6,6), (5,4). A new point arrives at (3,3). Using Euclidean distance, which class does k-NN assign?
Class A — the 3 nearest neighbors are (2,2) at d=1.41, (1,3) at d=2.0, (1,1) at d=2.83, all Class A
Class B — (5,4) is closer than (1,1) because the x-coordinate is nearer to 3
Tie — 2 neighbors from Class A and 1 from Class B among the 3 nearest
Class A — but only because (2,2) is the single nearest neighbor (k=1 result)
Answer: A. Class A — the 3 nearest neighbors are (2,2) at d=1.41, (1,3) at d=2.0, (1,1) at d=2.83, all Class A
ExplanationCompute distances from (3,3) to each point. Class A: d(3,3 to 1,1) = sqrt((3-1)^2+(3-1)^2) = sqrt(8) = 2.83. d(3,3 to 2,2) = sqrt(1+1) = 1.41. d(3,3 to 1,3) = sqrt(4+0) = 2.0. Class B: d(3,3 to 5,5) = sqrt(4+4) = 2.83. d(3,3 to 6,6) = sqrt(9+9) = 4.24. d(3,3 to 5,4) = sqrt(4+1) = 2.24. Sorted: (2,2) at 1.41, (1,3) at 2.0, (5,4) at 2.24, (1,1) at 2.83, (5,5) at 2.83, (6,6) at 4.24. Top 3: (2,2)=A, (1,3)=A, (5,4)=B. Majority vote: 2A vs 1B → Class A. This produces the classification because the algorithm assigns the majority label among the k=3 nearest neighbors.
Question 53 · Loss Functions · hard
You compute the cross-entropy loss for a single sample where the true label is class 2 (one-hot: [0, 0, 1]) and the model predicts probabilities [0.1, 0.2, 0.7]. Using ln(0.7) = -0.357, what is the loss?
ExplanationCross-entropy loss: L = -sum(y_i * ln(p_i)) where y is one-hot and p is predicted probabilities. Since y = [0, 0, 1], only the term where y_i=1 survives: L = -(0*ln(0.1) + 0*ln(0.2) + 1*ln(0.7)) = -ln(0.7) = -(-0.357) = 0.357. The loss only depends on the predicted probability for the TRUE class. If the model were perfectly confident (p=[0,0,1]), loss would be -ln(1)=0. If nearly wrong (p=[0,0,0.01]), loss would be -ln(0.01)=4.605. Our 0.357 indicates reasonable but imperfect confidence.
Question 54 · Linear Regression · hard
You have a dataset with features x = [1, 2, 3, 4, 5] and labels y = [2.2, 3.8, 6.1, 7.9, 10.1]. Using simple linear regression, the least-squares slope is m = 1.97 and intercept b = 0.14. What is the predicted value for x = 7, and what is the residual if the true value is 14.0?
Predicted = 1.97 × 7 + 0.14 = 13.93, Residual = 14.0 - 13.93 = 0.07; the model slightly underpredicts
Predicted = 1.97 × 7 = 13.79, Residual = 14.0 - 13.79 = 0.21; the intercept is not used for extrapolation
Predicted = 0.14 × 7 + 1.97 = 2.95, Residual = 14.0 - 2.95 = 11.05; slope and intercept are swapped in the formula
Predicted = 1.97 × 7 + 0.14 = 13.93, Residual = 13.93 - 14.0 = -0.07; residual is predicted minus actual
Answer: A. Predicted = 1.97 × 7 + 0.14 = 13.93, Residual = 14.0 - 13.93 = 0.07; the model slightly underpredicts
Explanationy_pred = mx + b = 1.97(7) + 0.14 = 13.79 + 0.14 = 13.93. Residual = actual - predicted = 14.0 - 13.93 = 0.07. The residual is positive, meaning the model underpredicts. Note: option D computes predicted-actual which gives the wrong sign convention (residual = actual - predicted by standard definition).
Question 55 · Confusion Matrix Metrics · hard
A binary classifier is evaluated on 200 test samples and produces the following confusion matrix results: True Positives (TP) = 60, False Positives (FP) = 20, False Negatives (FN) = 15, True Negatives (TN) = 105. Calculate the precision, recall, and F1 score for this classifier?
Precision = 60/(60+15) = 0.80, Recall = 60/(60+20) = 0.75, F1 = 2(0.80×0.75)/(0.80+0.75) ≈ 0.774; precision and recall definitions are swapped here
Precision = 60/200 = 0.30, Recall = 60/200 = 0.30, F1 = 0.30; both are calculated as TP divided by total samples
Precision = 0.75, Recall = 0.80, F1 = (0.75+0.80)/2 = 0.775; F1 is the arithmetic mean of precision and recall
Answer: A. Precision = 60/(60+20) = 0.75, Recall = 60/(60+15) = 0.80, F1 = 2(0.75×0.80)/(0.75+0.80) = 2(0.60)/1.55 ≈ 0.774
ExplanationPrecision = TP/(TP+FP) = 60/80 = 0.75 (of all predicted positive, 75% were correct). Recall = TP/(TP+FN) = 60/75 = 0.80 (of all actual positive, 80% were found). F1 = 2×P×R/(P+R) = 2×0.75×0.80/(0.75+0.80) = 1.20/1.55 ≈ 0.774. The swapped-formula choice mislabels which denominator belongs to precision versus recall, attaching FN to precision and FP to recall instead of the reverse. The TP/200 choice confuses these ratios with accuracy-style division by the full sample count, ignoring FP and FN entirely. The arithmetic-mean choice computes (0.75+0.80)/2 = 0.775 instead of the harmonic mean, which always understates versus the arithmetic mean whenever precision and recall differ — here 0.774 versus 0.775, a small but real gap that grows as the two metrics diverge further.
Question 56 · Matrix Inverse · hard
Given matrix A = [[2, 1], [5, 3]], compute A inverse. Verify by checking that A × A_inv = I. What value is returned?
You apply gradient descent to minimize f(x) = x² - 4x + 5. Starting at x₀ = 0 with learning rate α = 0.3, what are x₁ and x₂, and what is the minimum of f(x)?
Using f'(x) = 2x - 4: x₁ = 0 - 0.3(-4) = 1.2; x₂ = 1.2 - 0.3(2×1.2-4) = 1.2 - 0.3(-1.6) = 1.68; the minimum is at x = 2, where f(2) = 1.
Substituting incorrectly: f'(x) = 2x - 4; x₁ = 0 + 0.3(0-4) = -1.2; this wrongly adds the scaled derivative instead of subtracting it, which is not how gradient descent updates x.
f'(x) = x² - 4; x₁ = 0 - 0.3(-4) = 1.2; but this derivative of x² - 4x + 5 was computed incorrectly, since the actual derivative is 2x - 4.
Also using f'(x) = 2x - 4: x₁ = 0 - 0.3(-4) = 1.2; x₂ = 1.2 - 0.3(-1.6) = 1.68; but the minimum is incorrectly placed at x = 0, where f(0) = 5.
Answer: A. Using f'(x) = 2x - 4: x₁ = 0 - 0.3(-4) = 1.2; x₂ = 1.2 - 0.3(2×1.2-4) = 1.2 - 0.3(-1.6) = 1.68; the minimum is at x = 2, where f(2) = 1.
You normalize feature values using z-score standardization. Given data [10, 20, 30, 40, 50], the mean is 30 and standard deviation is √200 ≈ 14.14. What is the z-score of the value 50? Analyze the computation step by step and determine the exact numerical answer?
z = (50 - 30) / 14.14 = 20 / 14.14 ≈ 1.414; this means 50 is about 1.414 standard deviations above the mean
z = (50 - 30) / 200 = 0.10; the z-score divides by variance, not standard deviation
z = 50 / 30 = 1.667; z-score is the ratio of the value to the mean
z = (30 - 50) / 14.14 ≈ -1.414; the formula subtracts the value from the mean
Answer: A. z = (50 - 30) / 14.14 = 20 / 14.14 ≈ 1.414; this means 50 is about 1.414 standard deviations above the mean
ExplanationZ-score formula: z = (x - μ) / σ. For x=50: z = (50-30)/14.14 = 20/14.14 ≈ 1.414. This equals √2 exactly, since σ = √200 = 10√2, so z = 20/(10√2) = 2/√2 = √2. Option B divides by variance (σ²) instead of σ, giving a value in the wrong units. Option D reverses the subtraction order, which flips the sign and would wrongly place 50 below the mean instead of above it. Because σ = 10√2 exactly, the ratio 20/(10√2) reduces cleanly to √2 ≈ 1.4142, confirming 50 sits about 1.41 standard deviations above the mean of 30.
Question 59 · K-Means Clustering · hard
You perform k-means clustering with k=2 on points {1, 2, 8, 9, 10}. Initial centroids: c₁=1, c₂=10. After one iteration of assignment + update, what are the new centroids? Analyze the computation step by step and determine the exact numerical answer?
Assign: {1,2}→c₁ (closer to 1), {8,9,10}→c₂ (closer to 10). New c₁ = (1+2)/2 = 1.5, new c₂ = (8+9+10)/3 = 9.0
Assign: {1}→c₁, {2,8,9,10}→c₂. New c₁ = 1, new c₂ = (2+8+9+10)/4 = 7.25; point 2 is equidistant so goes to c₂
New c₁ = (1+2+8)/3 = 3.67, new c₂ = (9+10)/2 = 9.5; the algorithm splits at the midpoint of the data range
New c₁ = 1, new c₂ = 10; centroids never change after initialization with actual data points
Answer: A. Assign: {1,2}→c₁ (closer to 1), {8,9,10}→c₂ (closer to 10). New c₁ = (1+2)/2 = 1.5, new c₂ = (8+9+10)/3 = 9.0
ExplanationAssignment step: |1-1|=0 vs |1-10|=9 → 1 goes to c₁. |2-1|=1 vs |2-10|=8 → 2 goes to c₁. |8-1|=7 vs |8-10|=2 → 8 goes to c₂. |9-1|=8 vs |9-10|=1 → 9 goes to c₂. |10-1|=9 vs |10-10|=0 → 10 goes to c₂. Update step: c₁ = mean(1,2) = 1.5, c₂ = mean(8,9,10) = 9.0. Checking these new centroids against every point shows the assignments are unchanged (1 and 2 still stay closer to 1.5, and 8, 9, 10 still stay closer to 9.0), so the clustering has already converged after just this one iteration and would not shift on a second pass.
Question 60 · Correlation and Covariance · hard
You compute the covariance matrix of two features X and Y from 5 data points. Given: Var(X) = 4.0, Var(Y) = 9.0, Cov(X,Y) = -3.0. What is the Pearson correlation coefficient r, and what does it indicate?
r = Cov(X,Y) / (σ_X × σ_Y) = -3.0 / (2.0 × 3.0) = -3.0/6.0 = -0.5; this indicates a moderate negative linear relationship
r = Cov(X,Y) / (Var(X) × Var(Y)) = -3.0 / (4.0 × 9.0) = -3.0/36.0 = -0.083; dividing by variance product instead of std dev product
Dividing gives r = Cov(X,Y) / (Var(X) + Var(Y)) = -3.0 / 13.0 = -0.231; the denominator sums the variances
r = -3.0 / (4.0 + 9.0) × 2 = -0.462; the formula uses twice the sum of variances
Answer: A. r = Cov(X,Y) / (σ_X × σ_Y) = -3.0 / (2.0 × 3.0) = -3.0/6.0 = -0.5; this indicates a moderate negative linear relationship
ExplanationPearson r = Cov(X,Y)/(σ_X × σ_Y). σ_X = √Var(X) = √4 = 2. σ_Y = √Var(Y) = √9 = 3. r = -3/(2×3) = -0.5. This means X and Y have a moderate negative linear correlation: as X increases, Y tends to decrease. Option B incorrectly divides by the product of variances rather than standard deviations. Options C and D compound this error by never taking a square root at all, instead combining Var(X) and Var(Y) through addition (13.0) or a doubled sum (26.0), which produces -0.231 and -0.462 — values that don't correspond to any valid normalization of this covariance and drift further from the true r = -0.5 the more the formula is mangled.