Question 61 · Logistic Regression - Sigmoid · hard
In logistic regression, the sigmoid function is σ(z) = 1/(1+e^(-z)). If the model computes z = w·x + b = 2.0 for a sample, and e^(-2) ≈ 0.135, what is the predicted probability?
σ(2.0) = 1/(1 + e^(-2)) = 1/(1 + 0.135) = 1/1.135 ≈ 0.881; the model predicts about 88.1% probability for the positive class
σ(2.0) = 1/(1 + e^(2)) = 1/(1 + 7.389) ≈ 0.119; using e^(+z) instead of e^(-z) in the denominator
σ(2.0) = e^(-2)/(1 + e^(-2)) = 0.135/1.135 ≈ 0.119; the numerator should be e^(-z) not 1
σ(2.0) = 2.0/(1 + 2.0) = 0.667; substituting z directly instead of computing the exponential
Answer: A. σ(2.0) = 1/(1 + e^(-2)) = 1/(1 + 0.135) = 1/1.135 ≈ 0.881; the model predicts about 88.1% probability for the positive class
Explanationσ(z) = 1/(1+e^(-z)). For z=2: σ(2) = 1/(1+e^(-2)) = 1/(1+0.135) = 1/1.135 ≈ 0.881. Note: σ(z) + σ(-z) = 1, so σ(-2) ≈ 0.119 (which is what option B computes by using the wrong sign in the exponent). Since 0.881 is well above the 0.5 decision threshold, the model classifies this sample as the positive class with high confidence.
Question 62 · Naive Bayes Classification · hard
You train a naive Bayes classifier. P(spam) = 0.3, P(ham) = 0.7. For the word 'free': P('free'|spam) = 0.8, P('free'|ham) = 0.1. An email contains only the word 'free'. What is P(spam|'free') using Bayes theorem?
ExplanationBayes theorem: P(spam|free) = P(free|spam)P(spam) / P(free). P(free) = P(free|spam)P(spam) + P(free|ham)P(ham) = 0.8(0.3) + 0.1(0.7) = 0.24 + 0.07 = 0.31. P(spam|free) = 0.24/0.31 ≈ 0.774. Despite only 30% prior probability of spam, seeing 'free' raises it to 77.4% because 'free' is 8× more likely in spam.
Question 63 · PCA Variance Explained · hard
You perform Principal Component Analysis on a dataset with 3 features. The eigenvalues of the covariance matrix are lambda1=4.5, lambda2=1.2, lambda3=0.3. What percentage of total variance does PC1 explain, and how many components are needed to retain at least 95% of the variance?
Total variance = 4.5+1.2+0.3 = 6.0. PC1 explains 4.5/6.0 = 75.0%. PC1+PC2 = 5.7/6.0 = 95.0%. You need exactly 2 components to retain 95% of the variance
PC1 explains 4.5/3 = 150% because eigenvalues can exceed 100% for the first component
PC1 explains 4.5/(4.5×1.2×0.3) = 4.5/1.62 = 277.8%; the denominator is the product of eigenvalues
You always need all 3 components; PCA cannot reduce dimensionality without losing information
Answer: A. Total variance = 4.5+1.2+0.3 = 6.0. PC1 explains 4.5/6.0 = 75.0%. PC1+PC2 = 5.7/6.0 = 95.0%. You need exactly 2 components to retain 95% of the variance
ExplanationTotal variance = sum of all eigenvalues = 4.5 + 1.2 + 0.3 = 6.0. Variance explained by PC1 = 4.5/6.0 = 0.75 = 75%. By PC1+PC2 = (4.5+1.2)/6.0 = 5.7/6.0 = 0.95 = 95.0%. Since 2 components capture exactly 95%, you need 2 components. PC3 contributes only 5% variance and can be dropped with minimal information loss because eigenvalues directly measure the variance along each principal component direction.
Question 64 · One-Hot Encoding · hard
You apply one-hot encoding to a categorical feature 'Color' with values ['Red', 'Blue', 'Green', 'Red', 'Blue']. How many new binary columns are created, and what does the encoded matrix look like? Why might you drop one column?
3 columns created: Red=[1,0,0,1,0], Blue=[0,1,0,0,1], Green=[0,0,1,0,0]. You might drop one column (e.g., Green) to avoid the dummy variable trap — multicollinearity because the 3 columns sum to 1 for every row, making one column perfectly predictable from the others
5 columns created, one per data point (5 observations), because each row gets its own binary indicator column
2 columns: 'is_Red' and 'is_not_Red', because one-hot encoding always creates binary (yes/no) splits for one category
3 columns, but dropping one causes information loss because the model cannot distinguish the dropped category from missing data
Answer: A. 3 columns created: Red=[1,0,0,1,0], Blue=[0,1,0,0,1], Green=[0,0,1,0,0]. You might drop one column (e.g., Green) to avoid the dummy variable trap — multicollinearity because the 3 columns sum to 1 for every row, making one column perfectly predictable from the others
Explanation3 unique values → 3 binary columns. Row 1 (Red): [1,0,0]. Row 2 (Blue): [0,1,0]. Row 3 (Green): [0,0,1]. Row 4 (Red): [1,0,0]. Row 5 (Blue): [0,1,0]. The dummy variable trap occurs because Red + Blue + Green = 1 always, creating perfect multicollinearity. Dropping one column (say Green) loses no information because Green=1 when Red=0 AND Blue=0. This is essential for linear regression; tree-based models handle it without dropping.
Question 65 · Cross-Validation · hard
In k-fold cross-validation with k=5 on a dataset of 100 samples, how many samples are in each fold, how many training samples per iteration, and what is the total number of model trainings performed? Analyze the computation step by step and determine the exact answer?
Each fold: 100/5 = 20 samples. Per iteration: 80 training, 20 validation. Total: 5 models trained. Each sample appears exactly once as validation and 4 times as training, giving an unbiased performance estimate
Each fold: 50 samples (half for train, half for test). Total: 2 trainings because k-fold is just repeated holdout
Each fold: 20 samples, but only 1 model is trained on all 100 samples; the folds are used only for evaluation
Each fold: 100 samples because all data is used in every fold; total: 5 trainings each on full data
Answer: A. Each fold: 100/5 = 20 samples. Per iteration: 80 training, 20 validation. Total: 5 models trained. Each sample appears exactly once as validation and 4 times as training, giving an unbiased performance estimate
ExplanationWith k=5, the data is split into 5 equal folds of 20 samples each. In each iteration, 4 folds (80 samples) are used for training and 1 fold (20 samples) for validation. This rotates 5 times so every fold serves as validation exactly once. Total: 5 separate model trainings. The final metric is the average of all 5 validation scores. This gives a more robust estimate than a single train/test split because every sample contributes to both training and evaluation across the full procedure.
Question 66 · Gradient Boosting Update · hard
In gradient boosting with 3 weak learners, the initial prediction is y0 = mean(y) = 5.0 for all samples. Learning rate eta = 0.1. The first tree predicts residuals r1 = [2.0, -1.0, 3.0] for 3 samples. What are the updated predictions after the first tree?
y1 = y0 + eta × r1 = [5.0 + 0.1×2.0, 5.0 + 0.1×(-1.0), 5.0 + 0.1×3.0] = [5.20, 4.90, 5.30]; each prediction moves a small step in the direction of its residual
y1 = eta × r1 = [0.2, -0.1, 0.3]; the initial prediction is replaced entirely by the scaled residuals
y1 = y0 + r1 = [7.0, 4.0, 8.0]; the learning rate is not applied because it only affects later trees
y1 = [5.0, 5.0, 5.0]; the first tree's predictions are only used to compute the second tree's target
Answer: A. y1 = y0 + eta × r1 = [5.0 + 0.1×2.0, 5.0 + 0.1×(-1.0), 5.0 + 0.1×3.0] = [5.20, 4.90, 5.30]; each prediction moves a small step in the direction of its residual
ExplanationGradient boosting update rule: y_new = y_old + eta × tree_prediction. For each sample: y1[0] = 5.0 + 0.1×2.0 = 5.20. y1[1] = 5.0 + 0.1×(-1.0) = 4.90. y1[2] = 5.0 + 0.1×3.0 = 5.30. The learning rate eta=0.1 shrinks each tree's contribution, preventing overfitting by taking small steps. The next tree would then fit the new residuals: actual - [5.20, 4.90, 5.30]. This produces an additive ensemble that gradually reduces the overall prediction error.
Question 67 · Class Imbalance and Metrics · hard
You have a dataset of 1000 emails: 200 spam, 800 ham. You train a model that predicts ALL emails as ham (majority class baseline). What are the accuracy, precision, and recall for the spam class?
Accuracy = 800/1000 = 80%. Spam precision = 0/0 (undefined, no spam predictions made). Spam recall = 0/200 = 0%. This shows why accuracy alone is misleading on imbalanced datasets — 80% accuracy with zero ability to detect spam
Accuracy = 80%, precision = 80%, recall = 80%; all metrics equal accuracy for a baseline model
Accuracy = 20%, precision = 100%, recall = 100%; the model correctly identifies all ham which is the non-spam class
Accuracy = 50% because random guessing on a binary problem always gives 50%
Answer: A. Accuracy = 800/1000 = 80%. Spam precision = 0/0 (undefined, no spam predictions made). Spam recall = 0/200 = 0%. This shows why accuracy alone is misleading on imbalanced datasets — 80% accuracy with zero ability to detect spam
ExplanationThe model predicts EVERYTHING as ham. Confusion matrix: TP(spam)=0, FP(spam)=0, FN(spam)=200, TN(spam)=800. Accuracy = (0+800)/1000 = 80%. Spam precision = TP/(TP+FP) = 0/0 (undefined — no positive predictions). Spam recall = TP/(TP+FN) = 0/200 = 0%. The model completely fails at its primary task (detecting spam) despite 80% accuracy. This is the class imbalance trap: when one class dominates, accuracy becomes misleading and you need precision/recall/F1 to evaluate properly.
Question 68 · Bias-Variance Tradeoff · hard
You train a polynomial regression model with degree 1 (linear), degree 5, and degree 15 on 20 data points. The training MSE values are 8.2, 1.1, and 0.01 respectively. The test MSE values are 9.0, 3.5, and 45.0. Which model generalizes best, and what phenomenon explains the degree-15 results?
Degree 5 generalizes best (test MSE = 3.5). Degree 1 underfits (high train AND test error). Degree 15 overfits: near-zero training error but extremely high test error (45.0) because the 15-degree polynomial memorizes training noise, creating wild oscillations between data points that produce terrible predictions on unseen data
Degree 15 is best because it has the lowest training error (0.01), which means it learned the data perfectly
Degree 1 is best because simpler models always generalize better according to Occam's razor
All three models are equally good because the training errors show improvement from degree 1 to 15
Answer: A. Degree 5 generalizes best (test MSE = 3.5). Degree 1 underfits (high train AND test error). Degree 15 overfits: near-zero training error but extremely high test error (45.0) because the 15-degree polynomial memorizes training noise, creating wild oscillations between data points that produce terrible predictions on unseen data
ExplanationThe bias-variance tradeoff is visible: Degree 1 has high bias (underfitting) — both train (8.2) and test (9.0) error are high because a line cannot capture the data's true pattern. Degree 5 achieves good balance — train error 1.1 and test error 3.5 show the model captures the pattern without overfitting. Degree 15 has high variance (overfitting) — train error 0.01 means it memorized the 20 points, but test error 45.0 shows catastrophic failure on new data. With 15 parameters for 20 points, the model fits noise, producing a polynomial that oscillates wildly.
Question 69 · Bootstrap Sampling and OOB · hard
In a random forest with 100 trees, each tree is trained on a bootstrap sample of 1000 data points from the original 1000-point dataset. What fraction of unique samples does each tree see on average, and what are the unseen samples called?
Each tree sees approximately 63.2% of unique samples (about 632 unique points). The probability of NOT being selected in any of 1000 draws is (1 - 1/1000)^1000 ≈ e^(-1) ≈ 0.368, so 36.8% are out-of-bag (OOB) samples that can be used for validation without a separate test set
Each tree sees all 1000 unique samples because bootstrap sampling with replacement eventually selects every point
Each tree sees exactly 500 samples (50%) because bootstrap samples half the dataset
Each tree sees approximately 90% of samples because with 1000 draws from 1000 points, only a few are missed
Answer: A. Each tree sees approximately 63.2% of unique samples (about 632 unique points). The probability of NOT being selected in any of 1000 draws is (1 - 1/1000)^1000 ≈ e^(-1) ≈ 0.368, so 36.8% are out-of-bag (OOB) samples that can be used for validation without a separate test set
ExplanationBootstrap sampling draws N=1000 samples WITH replacement from N=1000 points. The probability a specific point is NOT drawn in a single draw is (N-1)/N = 999/1000. Over N draws: P(not selected) = (999/1000)^1000 ≈ e^(-1) ≈ 0.3679. So about 36.8% of points are never selected (out-of-bag), meaning each tree trains on approximately 63.2% unique points. OOB samples provide free validation: each point's OOB prediction averages only trees that didn't train on it, giving an unbiased error estimate without needing cross-validation.
Question 70 · Cosine Similarity · hard
You compute the cosine similarity between vectors A = [1, 2, 3] and B = [4, 5, 6]. Given that the dot product A·B = 32, ||A|| = sqrt(14) ≈ 3.742, and ||B|| = sqrt(77) ≈ 8.775, what is the cosine similarity?
cos(A,B) = A·B / (||A|| × ||B||) = 32 / (3.742 × 8.775) = 32 / 32.83 ≈ 0.9746. The vectors are nearly parallel (similarity close to 1) because they point in roughly the same direction, which makes sense since all components are positive and increasing
cos(A,B) = 32 / (14 × 77) = 32/1078 = 0.0297; dividing by the product of squared norms instead of norms
cos(A,B) = 32 / (14 + 77) = 32/91 = 0.352; using sum of squared norms instead of product of norms
cos(A,B) = (1×4 + 2×5 + 3×6) / 3 = 32/3 = 10.67; cosine similarity is the average of element-wise products
Answer: A. cos(A,B) = A·B / (||A|| × ||B||) = 32 / (3.742 × 8.775) = 32 / 32.83 ≈ 0.9746. The vectors are nearly parallel (similarity close to 1) because they point in roughly the same direction, which makes sense since all components are positive and increasing
ExplanationCosine similarity = dot(A,B) / (||A|| × ||B||). Dot product: 1×4 + 2×5 + 3×6 = 4+10+18 = 32. ||A|| = sqrt(1+4+9) = sqrt(14) ≈ 3.742. ||B|| = sqrt(16+25+36) = sqrt(77) ≈ 8.775. Cosine = 32/(3.742×8.775) = 32/32.83 ≈ 0.9746. This is very close to 1.0, indicating the vectors are nearly parallel. Cosine similarity ranges from -1 (opposite) to 1 (identical direction), and 0 means orthogonal. It measures direction similarity regardless of magnitude. This occurs because cosine similarity measures only the directional alignment, making it invariant to vector magnitude.
Question 71 · SVM Decision Boundary · hard
You build a support vector machine (SVM) with a linear kernel. The decision boundary is w·x + b = 0 where w = [2, -1] and b = 3. For a new point x = [1, 4], what is w·x + b, and on which side of the decision boundary does the point fall?
w·x + b = 2(1) + (-1)(4) + 3 = 2 - 4 + 3 = 1. Since w·x + b = 1 > 0, the point falls on the positive side of the decision boundary. The magnitude |1| / ||w|| = 1/sqrt(5) ≈ 0.447 gives the distance from the boundary
Computing w·x + b step by step: 2×1 + (-1)×4 + 3 = 2 - 4 - 3 = -5, so the point falls on the negative side of the decision boundary since -5 < 0
w·x + b = 2 + 4 + 3 = 9; taking absolute values of all terms, so the point is far from the boundary
w·x + b = (2-1)(1+4) + 3 = 1×5 + 3 = 8; multiplying the weight sum by the coordinate sum
Answer: A. w·x + b = 2(1) + (-1)(4) + 3 = 2 - 4 + 3 = 1. Since w·x + b = 1 > 0, the point falls on the positive side of the decision boundary. The magnitude |1| / ||w|| = 1/sqrt(5) ≈ 0.447 gives the distance from the boundary
ExplanationThe SVM decision function: f(x) = w·x + b = w1×x1 + w2×x2 + b. For w=[2,-1], x=[1,4], b=3: f = 2(1) + (-1)(4) + 3 = 2 - 4 + 3 = 1. Since f(x) = 1 > 0, the point is on the positive side (class +1). The signed distance from the hyperplane is f(x)/||w|| = 1/sqrt(4+1) = 1/sqrt(5) ≈ 0.447. Points with |f(x)| = 1 (i.e., f = ±1) lie on the margin boundaries, and the point [1,4] is exactly on the positive margin because f = 1.
Question 72 · Learning Rate Decay · hard
In a neural network, you use learning rate decay with the formula lr_t = lr_0 / (1 + decay × t). Starting with lr_0 = 0.1 and decay = 0.01, what is the learning rate at epoch 0, epoch 50, and epoch 100?
Epoch 0: 0.1/(1+0) = 0.1. Epoch 50: 0.1/(1+0.01×50) = 0.1/1.5 ≈ 0.0667. Epoch 100: 0.1/(1+0.01×100) = 0.1/2.0 = 0.05. The learning rate halves over 100 epochs, producing a smooth decay that allows large initial steps and fine-tuning later.
All three are 0.1 because the decay parameter only affects the loss function, not the learning rate
Epoch 0: 0.1, Epoch 50: 0.05, Epoch 100: 0.0; the learning rate decreases linearly to zero
Answer: A. Epoch 0: 0.1/(1+0) = 0.1. Epoch 50: 0.1/(1+0.01×50) = 0.1/1.5 ≈ 0.0667. Epoch 100: 0.1/(1+0.01×100) = 0.1/2.0 = 0.05. The learning rate halves over 100 epochs, producing a smooth decay that allows large initial steps and fine-tuning later.
ExplanationInverse time decay: lr(t) = lr_0/(1 + decay×t). Epoch 0: lr = 0.1/(1+0) = 0.1. Epoch 50: lr = 0.1/(1+0.5) = 0.1/1.5 = 0.0667. Epoch 100: lr = 0.1/(1+1.0) = 0.1/2.0 = 0.05. The decay is hyperbolic, not linear — it approaches zero asymptotically but never reaches it. Option D shows exponential decay (lr × 0.99^t), which is a different schedule. The inverse time decay is gentler: at epoch 50 it retains 66.7% vs exponential's 60.5%. This happens because the denominator grows linearly with time, producing a hyperbolic decay curve that asymptotically approaches zero.
Question 73 · Stratified Sampling · hard
You perform stratified sampling for train/test split on a dataset of 1000 samples with 900 class A and 100 class B (10% minority). With an 80/20 split, how many samples of each class are in the training and test sets?
Train: 720 class A + 80 class B = 800 total. Test: 180 class A + 20 class B = 200 total. Stratified sampling preserves the 90%/10% ratio in both splits, ensuring the minority class is represented proportionally in both training and evaluation.
Train: 800 class A + 0 class B = 800. Test: 100 class A + 100 class B = 200; the test set oversamples minority
Train: 80 class A + 720 class B = 800 total. Test: 20 class A + 180 class B = 200 total; this incorrectly swaps the class proportions, treating class B as the 90% majority instead of class A
Train: 750 class A + 50 class B = 800. Test: 150 class A + 50 class B = 200; random splitting without stratification
Answer: A. Train: 720 class A + 80 class B = 800 total. Test: 180 class A + 20 class B = 200 total. Stratified sampling preserves the 90%/10% ratio in both splits, ensuring the minority class is represented proportionally in both training and evaluation.
ExplanationStratified split maintains class proportions. 80% of class A: 0.8 × 900 = 720 for train, 180 for test. 80% of class B: 0.8 × 100 = 80 for train, 20 for test. Train total: 720+80 = 800 (90% A, 10% B). Test total: 180+20 = 200 (90% A, 10% B). Both sets have the same 90/10 ratio as the original dataset. Without stratification, random splitting could produce a test set with 0-5 class B samples by chance, making evaluation of minority class performance unreliable.
Question 74 · Multi-class Cross-Entropy Loss · hard
In a multi-class classification with 4 classes, the true label is class 2 (index 2). The model outputs raw logits [1.0, 2.0, 5.0, 1.0] before softmax. After softmax, the predicted probabilities are approximately [0.018, 0.050, 0.905, 0.018]. What is the cross-entropy loss using ln(0.905) = -0.0998?
CE = -ln(p_correct) = -ln(0.905) = 0.0998. Cross-entropy for one-hot labels reduces to the negative log of the predicted probability for the true class. Since the model assigns 90.5% to the correct class, the loss is small (0.0998), indicating a confident correct prediction
CE = -(ln(0.018) + ln(0.050) + ln(0.905) + ln(0.018)) = sum of all log probs = large number
CE = 1 - 0.905 = 0.095; cross-entropy is 1 minus the correct class probability
CE = 0.905 × ln(0.905) = 0.905 × (-0.0998) = -0.0903; multiply probability by its log
Answer: A. CE = -ln(p_correct) = -ln(0.905) = 0.0998. Cross-entropy for one-hot labels reduces to the negative log of the predicted probability for the true class. Since the model assigns 90.5% to the correct class, the loss is small (0.0998), indicating a confident correct prediction
ExplanationFor one-hot encoded labels, cross-entropy simplifies to CE = -sum(y_i × ln(p_i)). With true class = 2 (one-hot [0,0,1,0]): CE = -(0×ln(0.018) + 0×ln(0.050) + 1×ln(0.905) + 0×ln(0.018)) = -ln(0.905) = 0.0998. Only the true class term survives because all other y_i = 0. A loss of 0.0998 is quite low, reflecting the model's high confidence (90.5%) in the correct class. Perfect prediction (p=1.0) gives loss = 0, while random guessing (p=0.25) gives loss = ln(4) = 1.386.
Question 75 · Silhouette Score · hard
You compute the silhouette score for a point x in cluster A. The average distance to all other points in A is a(x) = 2.0, and the average distance to the nearest other cluster B is b(x) = 5.0. What is the silhouette score for this point, and what does it indicate?
s(x) = (b(x) - a(x)) / max(a(x), b(x)) = (5.0 - 2.0) / max(2.0, 5.0) = 3.0/5.0 = 0.6. A silhouette score of 0.6 indicates the point is reasonably well-clustered — it is much closer to its own cluster (distance 2) than to the nearest other cluster (distance 5)
s(x) = a(x) / b(x) = 2.0/5.0 = 0.4; the silhouette is the ratio of intra-cluster to inter-cluster distance
s(x) = (a(x) - b(x)) / max(a(x), b(x)) = -3/5 = -0.6; subtract b from a, not a from b
s(x) = (5.0 + 2.0) / 2 = 3.5; the silhouette score is the average of intra and inter distances
Answer: A. s(x) = (b(x) - a(x)) / max(a(x), b(x)) = (5.0 - 2.0) / max(2.0, 5.0) = 3.0/5.0 = 0.6. A silhouette score of 0.6 indicates the point is reasonably well-clustered — it is much closer to its own cluster (distance 2) than to the nearest other cluster (distance 5)
ExplanationSilhouette coefficient: s(x) = (b(x) - a(x)) / max(a(x), b(x)). With a=2.0, b=5.0: s = (5-2)/max(2,5) = 3/5 = 0.6. Range is [-1, 1]: s near 1 means well-clustered (far from other clusters, close to own). s near 0 means the point is on the boundary between clusters. s near -1 means the point is likely in the wrong cluster. Our score of 0.6 indicates good but not perfect clustering because b is 2.5× larger than a, showing meaningful separation between clusters.
Question 76 · Chi-Squared Feature Selection · hard
You perform feature selection using the chi-squared test on a binary classification dataset. Feature X has the contingency table: (X=0, Y=0): 30, (X=0, Y=1): 10, (X=1, Y=0): 20, (X=1, Y=1): 40. Calculate the expected count for cell (X=1, Y=1) under independence?
Total: 100. P(X=1) = 60/100 = 0.6, P(Y=1) = 50/100 = 0.5. Expected(X=1,Y=1) = 100 × 0.6 × 0.5 = 30. The observed count is 40 vs expected 30, indicating X and Y are positively associated — knowing X=1 makes Y=1 more likely than independence would predict.
Expected = (30+10+20+40)/4 = 25; the expected count is the mean of all cells
Expected = 40; under independence the expected equals the observed count
Expected = 60 × 50 = 3000; multiply the marginal totals directly without dividing by N
Answer: A. Total: 100. P(X=1) = 60/100 = 0.6, P(Y=1) = 50/100 = 0.5. Expected(X=1,Y=1) = 100 × 0.6 × 0.5 = 30. The observed count is 40 vs expected 30, indicating X and Y are positively associated — knowing X=1 makes Y=1 more likely than independence would predict.
ExplanationUnder the null hypothesis of independence: Expected(i,j) = (row_i_total × col_j_total) / N. Row X=1 total: 20+40 = 60. Column Y=1 total: 10+40 = 50. N = 100. Expected(X=1,Y=1) = 60×50/100 = 30. Observed is 40, which is 10 more than expected. The chi-squared statistic for this cell: (40-30)²/30 = 100/30 = 3.33. A large chi-squared total across all cells indicates the feature is informative for classification because its distribution differs significantly between classes.
Question 77 · DBSCAN Clustering · hard
Consider 1-dimensional DBSCAN clustering with epsilon (ε) = 2.0 and MinPts = 3, applied to six points on a number line: A = 0, B = 1, C = 2.5, D = 3.5, E = 5.0, F = 11. Using the standard DBSCAN convention where a point's ε-neighborhood includes the point itself and MinPts counts all points in that neighborhood, which points are core points, which are border points, and which point is noise?
Computing ε=2.0 neighborhoods (including each point itself): N(A)={A,B} (size 2), N(B)={A,B,C} (size 3, core), N(C)={B,C,D} (size 3, core), N(D)={C,D,E} (size 3, core), N(E)={D,E} (size 2), N(F)={F} (size 1). B, C, and D are core points; A is a border point because it lies in core point B's neighborhood, and E is a border point because it lies in core point D's neighborhood; F has no other point within ε and is noise.
If MinPts=3 is interpreted as requiring three neighbors other than the point itself, then A has only B, B has only A and C, C has only B and D, and D has only C and E within ε=2.0, so no point reaches the threshold and all six points, including B, C, and D, must be labeled noise.
Because A, B, C, D, and E form an unbroken chain in which each point sits within ε=2.0 of its immediate neighbor, standard DBSCAN treats the entire chain as core points belonging to one cluster, leaving only the isolated point F classified as noise.
B, C, and D are core points exactly as required by the density threshold, but A and E each have only one other point within ε=2.0 of themselves, which is below MinPts, so both A and E must be classified as noise alongside F rather than as border points.
Answer: A. Computing ε=2.0 neighborhoods (including each point itself): N(A)={A,B} (size 2), N(B)={A,B,C} (size 3, core), N(C)={B,C,D} (size 3, core), N(D)={C,D,E} (size 3, core), N(E)={D,E} (size 2), N(F)={F} (size 1). B, C, and D are core points; A is a border point because it lies in core point B's neighborhood, and E is a border point because it lies in core point D's neighborhood; F has no other point within ε and is noise.
ExplanationSince DBSCAN defines a point's ε-neighborhood as every point (including itself) within distance ε, computing this for ε=2.0 gives N(A)={A,B} (size 2), N(B)={A,B,C} (size 3), N(C)={B,C,D} (size 3), N(D)={C,D,E} (size 3), N(E)={D,E} (size 2), and N(F)={F} (size 1). Since MinPts=3, only B, C, and D meet the threshold and are core points. A is not core but lies within ε of core point B (distance 1.0), so it is density-reachable and becomes a border point; similarly E lies within ε of core point D (distance 1.5) and is also a border point. F's nearest neighbor is E at distance 6.0, far beyond ε=2.0, so F falls within no core point's neighborhood and is labeled noise. The key distinctions tested are that MinPts counts a point together with its own neighbors as one set (not neighbors alone), and that border-point status requires falling within a core point's ε-neighborhood rather than merely sitting next to another point in a chain.
Question 78 · Neural Network Architecture · hard
A neural network has input layer (3 neurons), hidden layer (4 neurons, ReLU activation), output layer (1 neuron, sigmoid). How many total trainable parameters (weights + biases) does this network have, and what is the result of computing each layer's contribution?
Total = (3*4 + 4) + (4*1 + 1) = 12+4+4+1 = 21 parameters. Input→Hidden: 3 inputs × 4 neurons = 12 weights + 4 biases = 16. Hidden→Output: 4 inputs × 1 neuron = 4 weights + 1 bias = 5. Total: 16+5 = 21. Each connection has one weight, and each neuron (except input) has one bias
Total = 3+4+1 = 8 parameters. Each neuron is one parameter, and weights are not counted separately because they are derived from the neuron values
Total = 3*4*1 = 12 parameters. The parameter count is the product of all layer sizes, with no additional bias terms
Total = (3*4) + (4*1) = 16 parameters. Biases are not trainable parameters — they are fixed constants set during initialization
Answer: A. Total = (3*4 + 4) + (4*1 + 1) = 12+4+4+1 = 21 parameters. Input→Hidden: 3 inputs × 4 neurons = 12 weights + 4 biases = 16. Hidden→Output: 4 inputs × 1 neuron = 4 weights + 1 bias = 5. Total: 16+5 = 21. Each connection has one weight, and each neuron (except input) has one bias
ExplanationFor each connection between layers: weights = (neurons_in × neurons_out), biases = neurons_out. Layer 1→2: weights = 3×4 = 12, biases = 4 because each of the 4 hidden neurons needs one bias. Subtotal = 16. Layer 2→3: weights = 4×1 = 4, biases = 1 because the output neuron has one bias. Subtotal = 5. Grand total = 16+5 = 21 trainable parameters. This produces the result that biases ARE trainable — they allow the activation function to shift left/right, which is essential for fitting data. Without biases, every activation function would pass through the origin. This calculation generalizes: for a network with layers [n1, n2, ..., nk], total params = Σ(n_i * n_{i+1} + n_{i+1}).
Question 79 · K-Means Clustering · medium
In k-means clustering with k=3, you initialize centroids at C1=(1,1), C2=(5,5), C3=(9,1). A data point P=(3,2) needs to be assigned. Compute the Euclidean distance from P to each centroid — what is the result, and which cluster does P belong to?
d(P,C1) = sqrt((3-1)^2 + (2-1)^2) = sqrt(4+1) = sqrt(5) ≈ 2.24. d(P,C2) = sqrt((3-5)^2 + (2-5)^2) = sqrt(4+9) = sqrt(13) ≈ 3.61. d(P,C3) = sqrt((3-9)^2 + (2-1)^2) = sqrt(36+1) = sqrt(37) ≈ 6.08. P is assigned to Cluster 1 (nearest centroid). After all points are assigned, centroids are recalculated as cluster means
d(P,C1) = |3-1| + |2-1| = 3. d(P,C2) = |3-5| + |2-5| = 5. d(P,C3) = |3-9| + |2-1| = 7. P is assigned to Cluster 1 using Manhattan distance, which is what k-means always uses
P is assigned to the cluster whose centroid has the closest x-coordinate only. Since C1 has x=1 (diff=2), C2 has x=5 (diff=2), they tie, and P is randomly assigned
P is assigned to Cluster 2 because k-means always assigns points to the middle cluster first, then redistributes in later iterations
Answer: A. d(P,C1) = sqrt((3-1)^2 + (2-1)^2) = sqrt(4+1) = sqrt(5) ≈ 2.24. d(P,C2) = sqrt((3-5)^2 + (2-5)^2) = sqrt(4+9) = sqrt(13) ≈ 3.61. d(P,C3) = sqrt((3-9)^2 + (2-1)^2) = sqrt(36+1) = sqrt(37) ≈ 6.08. P is assigned to Cluster 1 (nearest centroid). After all points are assigned, centroids are recalculated as cluster means
ExplanationK-means uses Euclidean distance: d = sqrt(Σ(xi-yi)^2). For P=(3,2): d(P,C1) = sqrt(4+1) = 2.24, d(P,C2) = sqrt(4+9) = 3.61, d(P,C3) = sqrt(36+1) = 6.08. Minimum distance is to C1, so P → Cluster 1. K-means then iterates: (1) assign all points to nearest centroid, (2) recalculate centroids as mean of cluster members, (3) repeat until convergence. The choice of initial centroids matters — poor initialization can lead to suboptimal clusters, which is why k-means++ is used in practice.
Question 80 · Feature Scaling and Normalization · medium
You normalize a feature using min-max scaling: X_norm = (X - X_min) / (X_max - X_min). Given marks = [45, 60, 75, 90, 100], compute the normalized value for X=75. Why is feature scaling critical before training algorithms like gradient descent?
X_norm = (75-45)/(100-45) = 30/55 ≈ 0.545. Min-max scales all values to [0,1]. Without scaling, features with large ranges (e.g., income: 0-1,000,000) dominate features with small ranges (e.g., age: 0-100) in distance calculations and gradient updates. Gradient descent oscillates inefficiently when features have very different scales, taking many more iterations to converge
X_norm = 75/100 = 0.75. Normalization simply divides by the maximum value. Scaling is optional and only affects visualization, not model training
X_norm = (75-70)/15 = 0.33, using z-score normalization with mean=70, std=15. Min-max and z-score always produce identical results
X_norm = 75 - 45 = 30. Normalization subtracts the minimum to shift values to start at 0. Scaling doesn't affect gradient descent because gradients are computed independently per feature
Answer: A. X_norm = (75-45)/(100-45) = 30/55 ≈ 0.545. Min-max scales all values to [0,1]. Without scaling, features with large ranges (e.g., income: 0-1,000,000) dominate features with small ranges (e.g., age: 0-100) in distance calculations and gradient updates. Gradient descent oscillates inefficiently when features have very different scales, taking many more iterations to converge
ExplanationMin-max: (75-45)/(100-45) = 30/55 ≈ 0.545. The range [45,100] is mapped to [0,1]: 45→0, 100→1, 75→0.545. Why it matters for gradient descent: if feature 1 ranges [0,1] and feature 2 ranges [0,1000000], the loss surface becomes elongated (elliptical contours). Gradient descent takes tiny steps along the large-range axis and large steps along the small-range axis, causing zigzagging. With scaled features, the contours become circular, enabling direct descent to the minimum. This can reduce training time by 10-100x.