Hack4Hack

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.

  1. Classifying emails as spam or not spam is:

    easy

    1. Regression
    2. Binary classification
    3. Clustering
    4. Reinforcement learning

    Answer: B. Binary classification

    Explanation: Two possible labels make it binary classification. Predicting a number would be regression.

  2. What is a feature in machine learning?

    easy

    1. The output label
    2. An input variable the model uses to make predictions
    3. A type of model
    4. 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.

  3. Which algorithm is commonly used for clustering?

    easy

    1. Linear regression
    2. K-means
    3. Logistic regression
    4. Naive Bayes

    Answer: B. K-means

    Explanation: K-means is unsupervised: it groups points around k centroids without labels.

  4. What is the learning rate in gradient descent?

    easy

    1. The number of epochs
    2. The size of each step taken along the negative gradient
    3. The accuracy of the model
    4. 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.

  5. What does a confusion matrix show for a classifier?

    medium

    1. Training time
    2. Counts of true positives, false positives, true negatives and false negatives
    3. The learning curve
    4. 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.

  6. What is k-fold cross-validation?

    medium

    1. Training k different models types
    2. Splitting data into k parts, training on k − 1 and validating on the remaining one, k times, then averaging
    3. Using k features
    4. 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.

  7. Which technique handles a heavily imbalanced dataset? (Select all that apply)

    medium

    1. Class weights in the loss
    2. Oversampling the minority class (e.g. SMOTE) on the training set
    3. Evaluating with precision, recall or PR-AUC
    4. 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.

  8. Why one-hot encode a categorical feature such as city?

    medium

    1. To reduce rows
    2. So the model does not treat category codes (Pune = 1, Delhi = 2) as ordered numbers
    3. To remove missing values
    4. 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.

  9. What does early stopping do?

    hard

    1. Stops training when the training loss reaches zero
    2. Stops training when the validation loss stops improving, to avoid overfitting
    3. Stops after one epoch
    4. 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.

  10. A decision tree splits on the feature that gives the biggest:

    hard

    1. Number of rows
    2. Reduction in impurity (Gini or entropy, i.e. information gain)
    3. Mean value
    4. 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.

  11. Why can a model with 95% accuracy in testing perform badly in production?

    hard

    1. Accuracy is always wrong
    2. Data drift or leakage: production data differs from training data, or the test set contained leaked information
    3. The server is slow
    4. 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.

  12. What is the main idea of a support vector machine?

    hard

    1. Average many trees
    2. Find the boundary with the widest margin between classes, defined by the closest points (support vectors)
    3. Cluster points into k groups
    4. 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

  1. Which statements about gradient boosting (e.g. XGBoost, LightGBM) are true? (Select all that apply)

    Machine Learning · medium

    1. Trees are built one after another, each correcting the previous errors
    2. Trees are built independently in parallel like a random forest
    3. A learning rate shrinks each tree’s contribution
    4. 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.

  2. Predicting house prices from size and location is which kind of problem?

    Machine Learning · easy

    1. Classification
    2. Regression
    3. Clustering
    4. 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.

  3. A model scores 99% on training data and 62% on test data. This is most likely:

    Machine Learning · easy

    1. Underfitting
    2. Overfitting
    3. Data leakage
    4. 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.

  4. Why does logistic regression use log-loss (cross-entropy) instead of mean squared error?

    Machine Learning · hard

    1. MSE cannot be computed for probabilities
    2. With a sigmoid, MSE gives a non-convex loss with weak gradients, while log-loss is convex and matches maximum likelihood
    3. Log-loss is faster to compute
    4. 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.

  5. The bias–variance decomposition of expected squared error is:

    Machine Learning · hard

    1. Bias + Variance
    2. Bias² + Variance + irreducible noise
    3. Bias × Variance
    4. Variance − Bias²

    Answer: B. Bias² + Variance + irreducible noise

    Explanation: E[(y − ŷ)²] = Bias[ŷ]² + Var[ŷ] + σ². The noise term σ² is a floor no model can beat.

  6. 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

    1. Precision 80%, recall 66.7%
    2. Precision 66.7%, recall 80%
    3. Both 80%
    4. 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%.

  7. What does an ROC-AUC of 0.5 mean?

    Machine Learning · medium

    1. Perfect classifier
    2. No better than random ranking
    3. 50% accuracy exactly
    4. 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.

  8. Increasing k in k-NN generally:

    Machine Learning · medium

    1. Increases variance, decreases bias
    2. Decreases variance, increases bias (smoother boundary)
    3. Has no effect
    4. 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.

Play the Daily Quiz at 4 PM IST