Machine Learning Practice Test
A static, self-check test on ML fundamentals, model evaluation, and algorithm selection, with a complete answer key
About This Practice Test
This practice test checks your understanding of core machine learning concepts: ML basics, the distinction between supervised and unsupervised learning, model evaluation and metrics, overfitting and regularization, common algorithms, feature engineering, and the basic math intuition behind learning. It is a static, self-check resource. Work through Section A (multiple choice) and Section B (short answer and scenarios) on paper or in a notebook first, without scrolling ahead. Then compare your responses to the Answer Key and Explanations at the end. Questions and answers are numbered consistently so you can grade yourself quickly and identify the topics worth reviewing.
Section A: Multiple Choice
Choose the single best answer for each question (A1-A12). Do not look at the answer key until you finish.
A1. Bias-variance tradeoff
A model with high bias and low variance most likely:
- A) Fits the training data almost perfectly but generalizes poorly
- B) Underfits, performing poorly on both training and test data
- C) Has very high test accuracy and low training accuracy
- D) Always improves as you add more training data
A2. Train/validation/test split
What is the primary purpose of holding out a separate test set that is never used during training or model selection?
- A) To increase the amount of data the model can learn from
- B) To tune hyperparameters such as learning rate
- C) To provide an unbiased estimate of generalization performance
- D) To balance the class distribution of the training data
A3. k-fold cross-validation
In k-fold cross-validation, the data is split into k folds and:
- A) The model is trained once on all folds simultaneously
- B) The model is trained k times, each time using k-1 folds for training and the remaining fold for validation
- C) Each fold is used only for testing and never for training
- D) The folds must always be selected at random without regard to class balance
A4. Precision vs. recall
For a binary classifier, recall (sensitivity) is defined as:
- A) TP / (TP + FP)
- B) TP / (TP + FN)
- C) TN / (TN + FP)
- D) (TP + TN) / (TP + TN + FP + FN)
A5. F1 score
The F1 score is:
- A) The arithmetic mean of precision and recall
- B) The harmonic mean of precision and recall
- C) The product of accuracy and recall
- D) The area under the ROC curve
A6. ROC-AUC
Which statement about ROC-AUC is correct?
- A) An AUC of 0.5 indicates a perfect classifier
- B) The ROC curve plots true positive rate against false positive rate across thresholds, and AUC is threshold-independent
- C) AUC can only be computed after fixing a single decision threshold
- D) AUC is the same as overall accuracy
A7. Signs of overfitting
Which pattern is the clearest sign that a model is overfitting?
- A) Training error and validation error are both high and similar
- B) Training error is low while validation error is substantially higher
- C) Training error and validation error are both low and similar
- D) Validation error is lower than training error
A8. L1 vs. L2 regularization
Compared with L2 (ridge) regularization, L1 (lasso) regularization is more likely to:
- A) Drive some coefficients exactly to zero, producing sparse models
- B) Increase all coefficients in magnitude
- C) Be unable to reduce overfitting at all
- D) Require the target variable to be normally distributed
A9. Gradient descent
In gradient descent, the parameters are updated by moving:
- A) In the direction of the gradient of the loss, scaled by the learning rate
- B) In the direction opposite to the gradient of the loss, scaled by the learning rate
- C) Randomly until the loss stops changing
- D) Toward the point of maximum loss
A10. Decision trees vs. linear models
Which statement best contrasts a decision tree with a linear (e.g., logistic) regression model?
- A) A single decision tree can capture non-linear interactions and axis-aligned splits, while a plain linear model assumes a linear relationship between features and the (log-odds of the) target
- B) Decision trees require feature scaling but linear models do not
- C) Linear models can only be used for classification, never regression
- D) Decision trees cannot overfit
A11. k-means vs. k-NN
Which statement correctly distinguishes k-means from k-nearest neighbors (k-NN)?
- A) Both are supervised classification algorithms
- B) k-means is an unsupervised clustering algorithm; k-NN is a supervised algorithm that predicts based on the labels of the nearest training examples
- C) k-NN partitions data into k clusters with no labels; k-means predicts labels
- D) Both require a target label to run
A12. Feature scaling and data leakage
When standardizing features (e.g., subtracting the mean and dividing by the standard deviation) for a model evaluated with a held-out test set, the correct practice is to:
- A) Fit the scaler on the entire dataset before splitting, then split into train and test
- B) Fit the scaler on the training set only, then apply those same statistics to transform the validation and test sets
- C) Fit a separate scaler on the test set using the test set's own statistics
- D) Skip scaling entirely because it never affects distance-based or gradient-based models
Section B: Short Answer / Scenario
Write a brief, reasoned answer for each applied question (B1-B6), then compare with the model answers below.
B1. Choosing a metric for an imbalanced problem
Scenario:
You are detecting fraudulent transactions where only about 0.5% of transactions are fraudulent. A model that labels every transaction as "not fraud" reports 99.5% accuracy. Explain why accuracy is misleading here and name one or two metrics you would use instead, with justification.
B2. Diagnosing and fixing overfitting
Scenario:
A gradient-boosted tree model reaches 99% training accuracy but only 72% validation accuracy. State what this gap indicates and propose at least three concrete changes to address it.
B3. Picking an algorithm for a task
Scenario:
You have a labeled dataset of 50,000 customers with 20 mostly tabular features (a mix of numeric and categorical) and a binary "will churn" target. You need a strong baseline that also gives some sense of which features matter. Which family of algorithms would you choose and why?
B4. Interpreting a confusion matrix
Scenario:
A binary classifier on 1,000 test cases (positive = "has disease") produces: TP = 80, FN = 20, FP = 100, TN = 800. Compute precision, recall, and accuracy, and comment on what the errors mean for this medical use case.
B5. Explaining a data leakage scenario
Scenario:
To predict whether a patient will be readmitted within 30 days, a teammate includes the feature "number of follow-up visits in the 60 days after discharge" and reports near-perfect validation accuracy. Explain why this is wrong and how it inflates performance.
B6. Supervised vs. unsupervised framing
Scenario:
A marketing team has customer purchase histories but no predefined labels and wants to discover natural groupings of customers to target with different campaigns. Is this a supervised or unsupervised problem? Name a suitable algorithm and explain how you would judge whether the result is useful.
Answer Key & Explanations
Correct answers with a one-line rationale for Section A, and model answers for Section B
Section A: Multiple Choice
- A1 - B. High bias, low variance means the model is too simple, so it underfits and does poorly on both training and test data.
- A2 - C. The test set must be untouched during training and model selection so it gives an unbiased estimate of generalization to new data.
- A3 - B. Each of the k iterations trains on k-1 folds and validates on the held-out fold; scores are then averaged, giving more stable estimates than a single split.
- A4 - B. Recall = TP / (TP + FN), the fraction of actual positives that the model correctly identifies. (A is precision; D is accuracy.)
- A5 - B. F1 is the harmonic mean of precision and recall, 2·(P·R)/(P+R), which penalizes a large imbalance between the two.
- A6 - B. ROC plots TPR vs. FPR over all thresholds; AUC summarizes performance across thresholds (0.5 is random, 1.0 is perfect).
- A7 - B. Low training error with much higher validation error is the classic overfitting signature; both-high means underfitting.
- A8 - A. L1's penalty has a constant-magnitude gradient that can push coefficients to exactly zero, yielding sparse, feature-selecting models; L2 shrinks but rarely zeroes them.
- A9 - B. Parameters move opposite to the gradient (the descent direction) by a step proportional to the learning rate, reducing the loss.
- A10 - A. Trees split on thresholds and naturally model interactions and non-linearities; a plain linear model assumes a linear relationship (in log-odds for logistic regression).
- A11 - B. k-means is unsupervised clustering (no labels); k-NN is supervised and predicts from the labels of the nearest training points.
- A12 - B. Fit the scaler on training data only and reuse those statistics on validation/test; fitting on the full data or the test set leaks test information.
B1. Choosing a metric for an imbalanced problem
Accuracy is misleading because the negative (non-fraud) class dominates: predicting "not fraud" for everything scores 99.5% while catching zero fraud, so accuracy rewards ignoring the rare class entirely. Better metrics focus on the positive class: precision and recall (and their combination, the F1 score), and the precision-recall curve / area under it, which is more informative than ROC-AUC under heavy imbalance. The right balance depends on costs: if missed fraud is expensive, prioritize recall; if false alarms are costly, weight precision. Confusion-matrix-based metrics make the rare-class errors explicit in a way accuracy hides.
B2. Diagnosing and fixing overfitting
The large gap between high training accuracy (99%) and much lower validation accuracy (72%) indicates overfitting: the model has memorized training-specific patterns and noise that do not generalize. Concrete fixes include: (1) reduce model complexity, e.g., lower the tree depth, reduce the number of estimators, or increase the minimum samples per leaf; (2) add regularization (e.g., L1/L2 penalties, or boosting parameters such as a smaller learning rate with early stopping); (3) gather more training data or use data augmentation; (4) remove noisy or leaky features and apply feature selection; and (5) use cross-validation to tune hyperparameters rather than fitting to a single split. Early stopping on the validation loss is especially effective for boosted models.
B3. Picking an algorithm for a task
For medium-sized tabular data with mixed numeric and categorical features, a gradient-boosted decision tree ensemble (e.g., XGBoost, LightGBM, or scikit-learn's HistGradientBoosting) is a strong default: it handles non-linearities and feature interactions, is relatively robust to feature scaling and monotonic transforms, and provides feature-importance estimates to indicate which features matter. A regularized logistic regression is a reasonable, more interpretable baseline if a linear decision boundary is adequate and you encode categoricals appropriately. Tree ensembles typically outperform deep neural networks on small-to-medium tabular datasets like this, so they are the pragmatic first choice.
B4. Interpreting a confusion matrix
With TP = 80, FN = 20, FP = 100, TN = 800: Precision = TP / (TP + FP) = 80 / 180 ≈ 0.44; Recall = TP / (TP + FN) = 80 / 100 = 0.80; Accuracy = (TP + TN) / 1000 = 880 / 1000 = 0.88. The model catches 80% of true disease cases (decent recall) but only 44% of its positive predictions are correct, so it raises many false alarms (100 FP). In a medical screening context the 20 false negatives are the most dangerous errors, since they are missed diseases; the 100 false positives mainly cause extra follow-up testing. Whether this tradeoff is acceptable depends on the cost of a missed diagnosis versus the cost of unnecessary follow-up, and the threshold could be lowered to raise recall further at the expense of precision.
B5. Explaining a data leakage scenario
This is target leakage. The feature "number of follow-up visits in the 60 days after discharge" is recorded after the prediction point and is a direct consequence of the outcome being predicted: patients who are readmitted typically have more post-discharge contact. The model therefore "sees the future" and uses information that would not be available at the moment a real prediction must be made (at or before discharge). Validation accuracy looks near-perfect because the feature is essentially a proxy for the label, but the model would fail in production where that information does not yet exist. The fix is to only use features available strictly before the prediction time and to define a clear cutoff so no post-outcome data enters the feature set.
B6. Supervised vs. unsupervised framing
This is an unsupervised problem because there are no predefined labels; the goal is to discover structure (natural customer segments) rather than predict a known target. A clustering algorithm such as k-means is suitable (with features scaled first, since k-means uses Euclidean distance), or hierarchical clustering / DBSCAN if cluster shapes or counts are unknown. Because there is no ground truth, usefulness is judged by internal validity metrics (e.g., silhouette score), the stability of clusters across runs or subsamples, and, most importantly, whether the resulting segments are interpretable and actionable for distinct marketing campaigns. The number of clusters k is typically chosen using methods like the elbow or silhouette analysis combined with business judgment.
Related Resources
Continue building your machine learning and data science skills
Machine Learning Course
A full course covering supervised and unsupervised learning, model evaluation, and practical workflows.
View CourseMachine Learning Fundamentals
Build the conceptual foundations behind the questions in this test, from bias-variance to regularization.
Learn FundamentalsPython Practice Test
Test the Python skills you need to implement and experiment with machine learning models.
Take TestData Science with Python Cheat Sheet
A quick reference for the libraries and workflows used in data science and machine learning.
Open Cheat Sheet