Machine Learning practice questions with answers
Practise machine learning questions at your own pace: overfitting, metrics, cross-validation, regularisation, trees, ensembles and SVMs. Pick an answer to see whether you are right and why. Nothing is timed or ranked here; for that, play the Daily Quiz at 4 PM IST.
Classifying emails as spam or not spam is:
easy
- Regression
- Binary classification
- Clustering
- Reinforcement learning
Answer: B. Binary classification
Explanation: Two possible labels make it binary classification. Predicting a number would be regression.
What is a feature in machine learning?
easy
- The output label
- An input variable the model uses to make predictions
- A type of model
- The loss value
Answer: B. An input variable the model uses to make predictions
Explanation: For house prices, features could be area, location and number of rooms; the label is the price.
Which algorithm is commonly used for clustering?
easy
- Linear regression
- K-means
- Logistic regression
- Naive Bayes
Answer: B. K-means
Explanation: K-means is unsupervised: it groups points around k centroids without labels.
What is the learning rate in gradient descent?
easy
- The number of epochs
- The size of each step taken along the negative gradient
- The accuracy of the model
- The size of the dataset
Answer: B. The size of each step taken along the negative gradient
Explanation: Too high and training diverges or bounces around; too low and it is very slow.
What does a confusion matrix show for a classifier?
medium
- Training time
- Counts of true positives, false positives, true negatives and false negatives
- The learning curve
- Feature importances
Answer: B. Counts of true positives, false positives, true negatives and false negatives
Explanation: Precision, recall, accuracy and F1 are all computed from these four counts.
What is k-fold cross-validation?
medium
- Training k different models types
- Splitting data into k parts, training on k − 1 and validating on the remaining one, k times, then averaging
- Using k features
- Repeating training k times on the same split
Answer: B. Splitting data into k parts, training on k − 1 and validating on the remaining one, k times, then averaging
Explanation: It gives a more reliable estimate than a single split, especially on small datasets. Use stratified folds for imbalanced classes.
Which technique handles a heavily imbalanced dataset? (Select all that apply)
medium
- Class weights in the loss
- Oversampling the minority class (e.g. SMOTE) on the training set
- Evaluating with precision, recall or PR-AUC
- Reporting accuracy only
Answer: A. Class weights in the loss; B. Oversampling the minority class (e.g. SMOTE) on the training set; C. Evaluating with precision, recall or PR-AUC
Explanation: Accuracy hides failure on the rare class. Resample only the training data, never the test set.
Why one-hot encode a categorical feature such as city?
medium
- To reduce rows
- So the model does not treat category codes (Pune = 1, Delhi = 2) as ordered numbers
- To remove missing values
- To scale features
Answer: B. So the model does not treat category codes (Pune = 1, Delhi = 2) as ordered numbers
Explanation: Each category becomes its own 0/1 column. For very many categories, target or embedding encodings are used.
What does early stopping do?
hard
- Stops training when the training loss reaches zero
- Stops training when the validation loss stops improving, to avoid overfitting
- Stops after one epoch
- Removes features early
Answer: B. Stops training when the validation loss stops improving, to avoid overfitting
Explanation: Keep the weights from the best validation epoch. It is a simple, effective form of regularisation.
A decision tree splits on the feature that gives the biggest:
hard
- Number of rows
- Reduction in impurity (Gini or entropy, i.e. information gain)
- Mean value
- Correlation with the index
Answer: B. Reduction in impurity (Gini or entropy, i.e. information gain)
Explanation: Each split tries to make the child nodes purer. Deep trees overfit; limit depth or use ensembles.
Why can a model with 95% accuracy in testing perform badly in production?
hard
- Accuracy is always wrong
- Data drift or leakage: production data differs from training data, or the test set contained leaked information
- The server is slow
- Production uses a different language
Answer: B. Data drift or leakage: production data differs from training data, or the test set contained leaked information
Explanation: Monitor input distributions and real outcomes after deployment, and validate on data split by time when the future matters.
What is the main idea of a support vector machine?
hard
- Average many trees
- Find the boundary with the widest margin between classes, defined by the closest points (support vectors)
- Cluster points into k groups
- Predict the next token
Answer: B. Find the boundary with the widest margin between classes, defined by the closest points (support vectors)
Explanation: The C parameter trades margin width against misclassified training points; kernels allow non-linear boundaries.
From past Daily Quizzes
Which statements about gradient boosting (e.g. XGBoost, LightGBM) are true? (Select all that apply)
Machine Learning · medium
- Trees are built one after another, each correcting the previous errors
- Trees are built independently in parallel like a random forest
- A learning rate shrinks each tree’s contribution
- It can overfit if you add too many trees
Answer: A. Trees are built one after another, each correcting the previous errors; C. A learning rate shrinks each tree’s contribution; D. It can overfit if you add too many trees
Explanation: Boosting is sequential: each tree fits the residual errors (gradients) of the current ensemble. Shrinkage and early stopping keep it from overfitting.
Predicting house prices from size and location is which kind of problem?
Machine Learning · easy
- Classification
- Regression
- Clustering
- Dimensionality reduction
Answer: B. Regression
Explanation: The target is a continuous number, so it is regression. Predicting a category (spam / not spam) would be classification.
A model scores 99% on training data and 62% on test data. This is most likely:
Machine Learning · easy
- Underfitting
- Overfitting
- Data leakage
- A perfect model
Answer: B. Overfitting
Explanation: A big gap between training and test performance means the model memorised the training set instead of learning patterns that generalise.
Why does logistic regression use log-loss (cross-entropy) instead of mean squared error?
Machine Learning · hard
- MSE cannot be computed for probabilities
- With a sigmoid, MSE gives a non-convex loss with weak gradients, while log-loss is convex and matches maximum likelihood
- Log-loss is faster to compute
- MSE always overfits
Answer: B. With a sigmoid, MSE gives a non-convex loss with weak gradients, while log-loss is convex and matches maximum likelihood
Explanation: Cross-entropy is the negative log-likelihood of a Bernoulli model. Combined with a sigmoid it is convex in the weights, so gradient descent finds the global optimum.
The bias–variance decomposition of expected squared error is:
Machine Learning · hard
- Bias + Variance
- Bias² + Variance + irreducible noise
- Bias × Variance
- Variance − Bias²
Answer: B. Bias² + Variance + irreducible noise
Explanation: E[(y − ŷ)²] = Bias[ŷ]² + Var[ŷ] + σ². The noise term σ² is a floor no model can beat.
A cancer test flags 100 people; 80 really have cancer. Out of 120 people who have cancer, 80 were flagged. What are precision and recall?
Machine Learning · medium
- Precision 80%, recall 66.7%
- Precision 66.7%, recall 80%
- Both 80%
- Precision 40%, recall 80%
Answer: A. Precision 80%, recall 66.7%
Explanation: Precision = TP / flagged = 80/100 = 80%. Recall = TP / actual positives = 80/120 ≈ 66.7%.
What does an ROC-AUC of 0.5 mean?
Machine Learning · medium
- Perfect classifier
- No better than random ranking
- 50% accuracy exactly
- The model is always wrong
Answer: B. No better than random ranking
Explanation: AUC is the chance a random positive is scored above a random negative. 0.5 is coin-flip ranking; 1.0 is perfect.
Increasing k in k-NN generally:
Machine Learning · medium
- Increases variance, decreases bias
- Decreases variance, increases bias (smoother boundary)
- Has no effect
- Always improves accuracy
Answer: B. Decreases variance, increases bias (smoother boundary)
Explanation: k = 1 follows every noisy point (high variance). Larger k averages over more neighbours, smoothing the boundary but possibly missing real detail.