Hack4Hack

Machine learning interview questions and answers

By Vikram · Updated 26 Oct 2026

Machine learning interviews for freshers and data roles focus on fundamentals: can you explain why a model fails, pick the right metric and avoid the classic mistakes? These questions come up in almost every ML interview.

Fundamentals

  • Supervised vs unsupervised: supervised learns from labelled examples (classification, regression); unsupervised finds structure without labels (clustering, dimensionality reduction).
  • Overfitting: great on training data, poor on new data. Fix it with more data, regularisation, simpler models, dropout or early stopping.
  • Underfitting: poor on both. Use a more expressive model or better features.
  • Bias–variance trade-off: expected error = bias² + variance + irreducible noise. Simple models have high bias; flexible models have high variance.
  • Train / validation / test: tune on validation, report once on the untouched test set.

Metrics

MetricFormulaUse when
PrecisionTP / (TP + FP)False alarms are costly (spam filters)
RecallTP / (TP + FN)Misses are costly (disease screening, fraud)
F12PR / (P + R)You need a balance on imbalanced data
ROC-AUCArea under the ROC curveComparing how well models rank positives
RMSE / MAEError size for regressionRMSE punishes large errors more

On imbalanced data, accuracy misleads: a model that always says “not fraud” is 99% accurate when 1% of cases are fraud, and useless.

Models

  • L1 vs L2 regularisation: L1 (Lasso) pushes some weights to exactly zero and selects features; L2 (Ridge) shrinks all weights smoothly.
  • Random forest vs gradient boosting: a forest averages many independent trees (bagging) to cut variance; boosting builds trees one after another, each fixing the last one's errors.
  • k-NN: predicts from the k nearest training points. Scale features first.
  • SVM: finds the widest-margin boundary; kernels give non-linear boundaries.
  • PCA: projects data onto the directions of maximum variance. It ignores labels.

Mistakes interviewers check for

  • Data leakage: fitting a scaler or encoder on the full dataset before splitting. Fit preprocessing on training data only, ideally inside a pipeline.
  • Tuning on the test set: an optimistic, invalid score. Use cross-validation or nested CV.
  • Ignoring the baseline: always compare with a simple model first.

Tip: Test your fundamentals daily with the machine learning questions with answers from the Daily Quiz, and put them to work in an ML competition or datathon.

Frequently asked questions

What is the difference between precision and recall?

Precision is the share of predicted positives that are correct, TP / (TP + FP). Recall is the share of actual positives the model found, TP / (TP + FN).

How do you prevent overfitting?

Get more data, regularise (L1, L2, dropout), simplify the model, use cross-validation and stop training early when validation loss stops improving.

What is data leakage in machine learning?

When information from outside the training data, often from the test set, leaks into training, for example scaling with statistics from the full dataset. It makes scores look better than real performance.

What is the difference between bagging and boosting?

Bagging trains models independently on bootstrap samples and averages them (random forest). Boosting trains models in sequence, each correcting the previous errors (XGBoost, LightGBM).

Play the Daily Quiz