Machine learning is still the backbone of most AI hiring, even in the age of chatbots. Fraud checks on UPI payments, loan approvals, product recommendations and delivery time estimates all run on classic ML models, and companies need people who understand them.
This page collects 28 machine learning interview questions with model answers, from basic questions for freshers to experienced-level and scenario-based rounds. Every answer is short enough to say out loud in about a minute.
I have seen many campus placement candidates explain random forests perfectly and then freeze when asked why their model's accuracy means nothing. So these answers focus on the "why", not just the definition.
Use the Save as PDF button above if you want an offline copy for revision.
What do machine learning interviews test?
Machine learning interviews test whether you understand how models learn, how to measure them honestly and how to pick the right tool for a messy business problem.
Most ML interview loops, from product startups to IT services firms, cover these layers:
| Layer | What they ask | Who gets it most |
|---|---|---|
| Fundamentals | Supervised vs unsupervised, overfitting, bias and variance | Freshers, every first round |
| Evaluation | Train-test split, cross-validation, precision, recall, ROC-AUC, RMSE | Everyone, often as follow-ups |
| Algorithms | Linear and logistic regression, trees, random forests, boosting, k-means, PCA | ML engineer and data science roles |
| Real-world judgement | Imbalanced data, leakage, missing values, drift | Experienced candidates and final rounds |
Engineering roles usually add a Python round with NumPy, pandas and scikit-learn. If you are unsure where ML sits in the bigger picture, revise AI vs ML vs deep learning first.
How to prepare for a machine learning interview in 2 weeks
The fastest plan combines concept revision, one honest project and spoken practice.
- Days 1 to 3: fundamentals. Revise supervised and unsupervised learning, overfitting, bias and variance, and train, validation and test splits. Write each in two lines.
- Days 4 to 6: metrics. Build a confusion matrix by hand for a small example and calculate precision, recall and F1 yourself. Interviewers test this more than any algorithm.
- Days 7 to 10: algorithms. For linear regression, logistic regression, decision trees, random forests, gradient boosting, k-means and PCA, know how each works, one strength and one weakness.
- Days 11 to 12: project. Pick one project and prepare the full story: data, baseline, features, validation, final metric and one mistake you fixed.
- Days 13 to 14: speak. Answer the questions on this page out loud, about 60 seconds each, or use our free AI interview practice guide.
If your Python is rusty, go through the Python for AI interview questions alongside this plan.
Basic machine learning interview questions for freshers
Expect these in the first technical round of campus placements. Keep each answer crisp and add one example.
1. What is machine learning?
EasyMachine learning is a branch of AI where systems learn patterns from data instead of following hand-written rules. You give the algorithm examples, it fits a model, and the model makes predictions on new data. A spam filter learns from thousands of labelled emails rather than a list of banned words. The trade-off: ML needs good data, and a model only knows the patterns present in what it was trained on.
Interviewer tip: Close with an example from daily life in India, such as UPI fraud alerts or food delivery time estimates.
2. What is the difference between supervised, unsupervised and reinforcement learning?
EasySupervised learning trains on labelled data, where each input has a known answer, like predicting house prices or tagging emails as spam. Unsupervised learning finds structure in unlabelled data, such as grouping customers into segments or reducing dimensions. Reinforcement learning trains an agent to take actions in an environment and learn from rewards, as in game-playing systems or robot control. Most business ML in India today is supervised, because companies already hold labelled history like past loan defaults.
3. What is the difference between classification and regression?
EasyClassification predicts a category, while regression predicts a continuous number. Will this customer churn (yes or no) is classification; how much will this customer spend next month is regression. The choice changes your algorithms and metrics: classification uses accuracy, precision, recall and ROC-AUC, while regression uses MAE, RMSE or R squared. Some problems can be framed either way, for example predicting a delivery delay in minutes or simply late versus on time.
4. What is overfitting, and what is underfitting?
EasyOverfitting is when a model learns the training data too closely, including its noise, so it performs well on training data but poorly on new data. Underfitting is when the model is too simple to capture the real pattern, so it does badly on both. You spot overfitting when training accuracy is much higher than validation accuracy. Fixes include more data, simpler models, regularisation, early stopping and cross-validation. Underfitting needs better features or a more flexible model.
Interviewer tip: Draw the classic curve of training vs validation error if there is a whiteboard.
5. Why do we split data into training, validation and test sets?
EasyWe split data so we can measure how a model performs on data it has never seen. The training set fits the model, the validation set tunes hyperparameters and compares models, and the test set gives one final, unbiased estimate. If you tune on the test set, it stops being unseen and your reported score becomes too optimistic. A common starting split is 70, 15 and 15 percent, but for time-based data you should split by date, not randomly.
6. What is a feature, and what is feature engineering?
EasyA feature is an input variable the model uses to make a prediction, such as age, city or number of past orders. Feature engineering is creating better inputs from raw data: extracting the day of week from a timestamp, computing average order value, or encoding categories as numbers. Good features often improve a model more than switching algorithms. The risk is building features that use information not available at prediction time, which causes data leakage.
7. Explain linear regression and its key assumptions.
MediumLinear regression predicts a number as a weighted sum of input features plus a constant, and it learns the weights by minimising the squared error between predictions and actual values. Its classic assumptions are a linear relationship, independent errors, constant error variance (homoscedasticity), normally distributed residuals for valid inference, and no strong multicollinearity between features. In practice, it is a strong, explainable baseline. If the relationship is curved, you can add polynomial or log features while keeping the model linear in its weights.
Machine learning interview questions and answers: algorithms and metrics
These come up in almost every ML interview, for freshers and experienced candidates alike.
1. What is the bias-variance trade-off?
MediumThe bias-variance trade-off says that prediction error comes partly from bias (wrong, oversimplified assumptions) and partly from variance (sensitivity to the particular training sample). Simple models like linear regression tend to have high bias and low variance; deep trees have low bias and high variance. As you increase model complexity, bias usually falls and variance rises, so the goal is the sweet spot with the lowest validation error. Ensembles like random forests reduce variance by averaging many trees.
Interviewer tip: Link it back to overfitting: high variance is overfitting, high bias is underfitting.
2. What is regularisation? Explain L1 vs L2.
MediumRegularisation adds a penalty for large model weights to the loss function, which discourages overly complex models and reduces overfitting. L1 (Lasso) penalises the absolute values of weights and can push some to exactly zero, so it also acts as feature selection. L2 (Ridge) penalises squared weights, shrinking them smoothly without removing features, and handles correlated features well. Elastic Net combines both. The regularisation strength is a hyperparameter you tune with cross-validation.
3. What is cross-validation, and why use k-fold?
MediumCross-validation estimates how a model will perform on unseen data by training and testing it on different splits. In k-fold cross-validation, you divide data into k parts, train on k minus 1 parts and validate on the remaining one, repeat k times, then average the scores. It gives a more stable estimate than a single split, especially on small datasets. Use stratified k-fold for imbalanced classes and time-series splits for temporal data, where shuffling would leak the future into the past.
4. Explain precision, recall and F1 score.
MediumPrecision is the share of predicted positives that are actually positive; recall is the share of actual positives the model catches. F1 score is the harmonic mean of the two, useful when you need a single number that balances them. For a cancer screening model, high recall matters most because missing a patient is costly. For a spam filter, high precision matters because blocking a real email annoys users. Changing the classification threshold trades one against the other.
Interviewer tip: Be ready to calculate all three from a small confusion matrix on paper.
5. What is ROC-AUC, and when can it mislead you?
MediumThe ROC curve plots the true positive rate against the false positive rate across all thresholds, and AUC is the area under it. An AUC of 0.5 means random ranking and 1.0 means perfect separation; you can read it as the probability that a random positive is scored above a random negative. On heavily imbalanced data, such as fraud at under 1 percent, ROC-AUC can look high while precision stays poor. The precision-recall curve is often more informative there.
6. What is gradient descent?
MediumGradient descent is an optimisation method that repeatedly moves model parameters in the direction that reduces the loss, using the gradient as a guide. The learning rate controls the step size: too large and training diverges, too small and it crawls. Batch gradient descent uses all data per step, stochastic uses one example, and mini-batch uses small groups, which is the common default in deep learning. Variants such as momentum and Adam adapt the steps to train faster and more stably.
7. How does logistic regression work, and why is it called regression?
MediumLogistic regression is a classification model that passes a weighted sum of features through a sigmoid function to output a probability between 0 and 1. It is called regression because it models the log-odds of the positive class as a linear function of the features. It is trained by minimising log loss, also called cross-entropy. You then pick a threshold, often 0.5 but tuned to business costs, to turn probabilities into classes. Its weights are easy to explain, which banks and lenders value.
8. How does a decision tree decide where to split?
MediumA decision tree tries candidate splits on each feature and picks the one that makes the child nodes most pure. For classification, purity is measured with Gini impurity or entropy, where the drop in entropy is called information gain. For regression trees, it picks the split that most reduces squared error. Trees are easy to explain and handle non-linear patterns, but a fully grown tree overfits badly, so you limit depth, set minimum samples per leaf or prune it.
9. What is the difference between random forest and gradient boosting?
MediumRandom forest is a bagging method: it trains many deep trees independently on bootstrapped samples with random feature subsets, then averages their votes, which mainly reduces variance. Gradient boosting trains shallow trees one after another, where each new tree corrects the errors of the previous ones, which mainly reduces bias. Boosting libraries such as XGBoost, LightGBM and CatBoost often win on tabular data but need more careful tuning. Random forest is a forgiving default when you need a decent model quickly.
Interviewer tip: Expect a follow-up on which one parallelises more easily. The answer is random forest.
10. How does k-means clustering work, and how do you choose k?
MediumK-means groups data into k clusters by repeating two steps: assign each point to its nearest centroid, then move each centroid to the mean of its assigned points, until assignments stop changing. You choose k with the elbow method (where the drop in within-cluster error flattens), silhouette scores, and most importantly whether the clusters make business sense. K-means assumes roughly round, similar-sized clusters and is sensitive to feature scale, so standardise features first and try several random starts.
11. What is PCA, and when would you use it?
MediumPCA (principal component analysis) is a dimensionality reduction technique that finds new, uncorrelated directions, called principal components, that capture the most variance in the data. You keep the top few components and drop the rest. Use it to compress many correlated features, speed up training, reduce noise or plot high-dimensional data in two dimensions. Standardise features before PCA, or large-scale features will dominate. The trade-off is interpretability, because each component mixes many original features.
Machine learning interview questions for experienced candidates
These separate people who have trained models on real, messy data from people who have only followed tutorials.
1. How do you handle imbalanced data?
HardStart by choosing the right metric, such as precision, recall, F1 or PR-AUC, because accuracy hides the minority class. Then try class weights in the loss function, resampling (undersampling the majority class or oversampling the minority, for example with SMOTE) and tuning the decision threshold to match business costs. Always resample only the training data, never the validation or test sets. In my experience, threshold tuning and class weights solve most cases before you need fancy resampling.
2. What is data leakage, and how do you prevent it?
HardData leakage is when information that would not be available at prediction time sneaks into training, making offline scores look far better than real performance. Common causes are features computed after the outcome (like a refund flag when predicting fraud), scaling or imputing on the full dataset before splitting, and random splits on time-series data. Prevent it by splitting first, fitting preprocessing inside a pipeline on training folds only, and asking for every feature: would I know this at prediction time?
Interviewer tip: Suspiciously high accuracy is the classic leakage signal. Say so before the interviewer does.
3. How do you handle missing values and categorical features?
MediumFor missing values, first ask why they are missing, because the reason often carries signal. Options include dropping rows or columns with heavy gaps, imputing with the median or most frequent value, model-based imputation, or adding a was-missing indicator. For categorical features, use one-hot encoding for low-cardinality columns, and target or frequency encoding for high-cardinality ones like PIN codes, fitted carefully to avoid leakage. Tree-based libraries such as LightGBM and CatBoost can handle categories natively.
4. What is a neural network, and what does backpropagation do?
MediumA neural network is a model made of layers of connected units, where each unit computes a weighted sum of its inputs and applies a non-linear activation such as ReLU. Stacking layers lets it learn complex patterns. Backpropagation computes how much each weight contributed to the loss by applying the chain rule backwards through the network, and gradient descent then updates the weights. See what a neural network is for a visual walkthrough.
5. What are vanishing gradients, and how are they addressed?
HardVanishing gradients happen when gradients shrink as they flow backwards through many layers, so early layers barely learn. Sigmoid and tanh activations made this common in older deep networks and RNNs. Fixes include ReLU-style activations, careful weight initialisation such as He or Xavier, batch normalisation, residual connections and gated units like LSTMs and GRUs for sequences. Exploding gradients, the opposite problem, are often handled with gradient clipping. Residual connections are a big reason modern transformer models train well.
6. How do you deploy a model and monitor it in production?
HardPackage the model with the exact same preprocessing used in training, usually as a pipeline, and serve it through a batch job or an API. Then monitor three things: data drift (input distributions shifting), prediction drift and actual performance once true labels arrive. Log inputs and outputs, set alerts and plan scheduled retraining. A model trained on pre-festival shopping data, for example, may behave very differently during Diwali sales. Version models and data so you can roll back quickly.
Scenario-based machine learning interview questions
Structure each answer as: clarify the goal, check the data, propose a baseline, name the metric and the risks.
1. Your fraud model has 99% accuracy, but the business says it is useless. What went wrong?
HardIf fraud is under 1 percent of transactions, a model that predicts not fraud for everything scores 99 percent accuracy and catches nothing. I would check the confusion matrix and switch to recall, precision and PR-AUC for the fraud class. Then I would agree the cost of a missed fraud versus a wrongly blocked payment with the business, tune the threshold to that trade-off, and add class weights. The fix starts with the metric, not the algorithm.
Interviewer tip: Interviewers love the phrase "accuracy paradox". Use it, then explain it.
2. Training accuracy is 99% but test accuracy is 70%. What do you do?
MediumA gap that large signals overfitting, or a mismatch between training and test data. First, check for leakage and confirm the two sets come from the same distribution. Then simplify: limit tree depth, add regularisation, reduce features, use early stopping or get more data. Use cross-validation to confirm the fix is real and not luck. If the test data is genuinely different, for example from a new city, the problem is distribution shift, and you need representative training data.
3. A model worked well offline but performs worse after deployment. How would you investigate?
HardFirst, confirm the production pipeline computes features exactly as training did, because training-serving skew is a common cause. Next, compare live input distributions with training data to detect drift, such as new user segments or a changed app flow. Then check whether offline validation leaked future information, which would have inflated the original score. Finally, look at label delays: early production metrics can be noisy. Each check narrows the cause before you retrain anything.
4. How would you build a model to predict loan default for a lender?
HardI would clarify the goal (approve or reject, or set a risk-based limit), then gather application, repayment and bureau data available at decision time only. I would start with logistic regression as an explainable baseline, then try gradient boosting and compare on a time-based validation split using recall, precision and AUC. I would also check fairness across groups, since lending decisions are regulated and must be explainable. The final choice balances accuracy with explainability for credit and compliance teams.
Common mistakes in machine learning interviews
The most common mistake is reciting algorithm definitions without saying when you would use them.
- Quoting accuracy alone. Always mention the class balance and a second metric.
- No baseline. Strong candidates compare their model with a simple baseline, such as predicting the average or the majority class.
- Ignoring leakage. If your project score looks too good, explain how you checked that it was real.
- Jumping to deep learning. For tabular data, gradient boosting or logistic regression is often the better first answer.
- Bluffing on maths. If you forget a formula, explain the intuition and say how you would verify it.
My contrarian advice: stop chasing Kaggle-style leaderboard scores for your resume. One project where you can explain your validation choice, your metric and one mistake you fixed will impress an interviewer far more than a 0.2 percent accuracy gain. If you also want GenAI roles, pair this page with our generative AI interview questions.
Last-week plan before your ML interview
In the final week, revise and rehearse rather than learning new algorithms.
- Day 1: Re-derive precision, recall and F1 from a confusion matrix.
- Day 2: Revise bias and variance, regularisation and cross-validation with one example each.
- Day 3: Explain trees, random forests and boosting out loud in under a minute each.
- Day 4: Rehearse your project story with numbers.
- Day 5: Practise the scenario questions on this page.
- Days 6 and 7: Do two timed mock interviews and rest.
If the role mixes ML with statistics and business cases, also skim our data scientist interview questions.
Your interview prep checklist
- Explain supervised, unsupervised and reinforcement learning with one example each.
- Calculate precision, recall and F1 from a confusion matrix on paper.
- Know how linear regression, logistic regression, trees, random forests, boosting, k-means and PCA work.
- Prepare one answer each on imbalanced data, data leakage and overfitting.
- Rehearse one project story: data, baseline, features, validation, metric, mistake fixed.
- Practise 10 answers out loud, about 60 seconds each.