Interview questions & answers

Machine Learning interview questions & answers

What are the most common Machine Learning interview questions?

Machine learning is a field of artificial intelligence where algorithms learn patterns from data to make predictions or decisions without being explicitly programmed for each case. Models are trained on data, evaluated for generalization, and tuned to balance fitting and flexibility. Interviews test the types of learning, overfitting and the bias-variance tradeoff, evaluation metrics, regularization, and how core algorithms work.

Updated 2026-06-18 · 15 real, commonly-asked questions with answers.

Key takeaways

  • Machine learning is a field of artificial intelligence where algorithms learn patterns from data to make predictions or decisions without being explicitly programmed for each case.
  • Core areas to revise for Machine Learning: Supervised vs unsupervised, Overfitting & regularization, Bias-variance tradeoff, Evaluation metrics, Cross-validation.
  • This guide answers 15 of the most-asked Machine Learning interview questions — rehearse them in OnJob's free AI mock interview.
Supervised vs unsupervisedOverfitting & regularizationBias-variance tradeoffEvaluation metricsCross-validationGradient descentBagging & boostingClassification vs regression

Top 15 Machine Learning interview questions

Q1.What is the difference between supervised and unsupervised learning?

Supervised learning trains on labeled data, where each example has a known target, so the model learns to predict outputs (classification or regression). Unsupervised learning works on unlabeled data to find hidden structure, such as clustering similar items or reducing dimensionality. Supervised learning needs labels and predicts; unsupervised learning discovers patterns without labels.

Q2.What is overfitting and how do you prevent it?

Overfitting is when a model learns the training data too well, including its noise, so it performs great on training data but poorly on new, unseen data. You prevent it with more training data, simpler models, regularization (L1/L2), cross-validation, early stopping, dropout in neural networks, and pruning in trees. The goal is a model that generalizes rather than memorizes.

Q3.Explain the bias-variance tradeoff.

Bias is error from overly simplistic assumptions that cause the model to underfit, missing real patterns. Variance is error from excessive sensitivity to training data that causes overfitting. The tradeoff is that reducing bias (a more complex model) tends to increase variance, and vice versa. The aim is the sweet spot that minimizes total error on unseen data, balancing underfitting and overfitting.

Q4.What is the difference between classification and regression?

Classification predicts a discrete category or label, such as spam versus not spam, with outputs from a finite set of classes. Regression predicts a continuous numeric value, such as a house price or temperature. Both are supervised learning, but they differ in output type and use different loss functions and evaluation metrics.

Q5.What is cross-validation and why is it used?

Cross-validation evaluates a model's generalization by splitting the data into multiple folds, training on some and validating on the rest, then rotating so each fold serves as validation once. K-fold cross-validation averages the results across k splits. It gives a more reliable performance estimate than a single train-test split and helps detect overfitting and tune hyperparameters.

Q6.What is the difference between precision and recall?

Precision is the fraction of predicted positives that are actually positive (true positives over all predicted positives), measuring how trustworthy positive predictions are. Recall is the fraction of actual positives the model correctly identified (true positives over all actual positives), measuring coverage. There is usually a tradeoff: optimizing one often lowers the other, and the F1 score is their harmonic mean.

Q7.What is regularization and what do L1 and L2 do?

Regularization adds a penalty on model complexity to the loss function to discourage overfitting. L1 (Lasso) penalizes the sum of absolute weights and can shrink some weights exactly to zero, performing feature selection. L2 (Ridge) penalizes the sum of squared weights, shrinking them toward zero but rarely to exactly zero, which spreads influence across features. Both trade a little training fit for better generalization.

Q8.What is the difference between bagging and boosting?

Bagging (bootstrap aggregating) trains many models in parallel on random subsets of the data and averages their predictions to reduce variance, as in random forests. Boosting trains models sequentially, where each new model focuses on the errors of the previous ones, reducing bias, as in gradient boosting and AdaBoost. Bagging mainly fights variance; boosting mainly fights bias.

Q9.What is gradient descent?

Gradient descent is an optimization algorithm that minimizes a loss function by iteratively adjusting model parameters in the opposite direction of the gradient (the direction of steepest increase). The learning rate controls the step size: too large can overshoot or diverge, too small is slow. Variants include batch, stochastic (one sample at a time), and mini-batch gradient descent.

Q10.What is the difference between a training, validation, and test set?

The training set is used to fit the model's parameters. The validation set is used during development to tune hyperparameters and compare models, guiding choices without touching the test set. The test set is held out until the very end to give an unbiased estimate of how the final model generalizes to unseen data. Mixing these roles leaks information and inflates performance estimates.

Q11.What is a confusion matrix?

A confusion matrix is a table that summarizes a classifier's performance by showing counts of true positives, true negatives, false positives, and false negatives. From it you derive metrics like accuracy, precision, recall, and F1 score. It is especially useful for understanding error types in imbalanced datasets, where accuracy alone can be misleading.

Q12.Why can accuracy be misleading for imbalanced datasets?

Accuracy is the fraction of correct predictions, but with imbalanced classes a model can score high by always predicting the majority class while missing the rare class entirely. For example, if 99% of cases are negative, predicting negative always gives 99% accuracy yet catches no positives. Precision, recall, F1, and ROC-AUC give a truer picture for imbalanced data.

Q13.What is the curse of dimensionality?

The curse of dimensionality refers to problems that arise when data has very many features: the volume of the feature space grows so fast that data becomes sparse, distances between points become less meaningful, and models need exponentially more data to generalize. It increases overfitting risk and computation. Dimensionality reduction (like PCA) and feature selection help mitigate it.

Q14.What is the difference between parameters and hyperparameters?

Parameters are values the model learns from the training data, such as the weights in a linear model or neural network. Hyperparameters are settings configured before training that control the learning process, such as the learning rate, number of trees, or regularization strength. Parameters are learned; hyperparameters are chosen, often via tuning on a validation set.

Q15.What is the difference between underfitting and overfitting?

Underfitting is when a model is too simple to capture the underlying pattern, performing poorly on both training and test data (high bias). Overfitting is when a model is too complex and fits noise in the training data, performing well on training data but poorly on test data (high variance). The goal is a balanced model that captures the real signal and generalizes.

Free AI mock interview

Practise Machine Learning out loud

Reading answers is step one. Rehearse them in OnJob's free AI mock interview, get instant feedback, then apply to AI-matched jobs in one click.

Create my free profile — free