Friday, September 11, 2026
HomeData ScienceMachine Learning Interview Questions and Answers – Top 60 for 2026

Machine Learning Interview Questions and Answers – Top 60 for 2026

Table of Content

Machine learning interviews at top companies — Google, Amazon, Meta, Microsoft, startups — test both theoretical understanding and practical implementation skills. This guide covers the 60 most commonly asked machine learning interview questions with detailed answers, organised by topic so you can study systematically. Whether you are preparing for a data scientist, ML engineer, or research scientist role, these questions appear in virtually every ML interview loop.

Supervised Learning Interview Questions

Q1. What is supervised learning? Give three real-world examples.
Supervised learning trains a model on labelled input-output pairs so it can predict outputs for new, unseen inputs. The “supervision” is the label — a human has already provided the correct answer for every training example. Real-world examples: (1) Email spam detection — the input is an email’s text and metadata, the label is spam or not-spam. (2) House price prediction — the input is features like area, location, and number of rooms, the label is the sale price. (3) Medical diagnosis — the input is patient symptoms and test results, the label is the diagnosis. Supervised learning splits into classification (categorical output) and regression (continuous output).

Q2. What is the difference between classification and regression?
Classification predicts a discrete category — which class does this input belong to? Binary classification has two classes (fraud/not-fraud); multiclass has more than two (cat/dog/bird). Regression predicts a continuous numeric value — how much, how long, how many? The loss functions differ: classification commonly uses cross-entropy loss; regression uses mean squared error or mean absolute error. The evaluation metrics also differ — accuracy, precision, recall, F1, and AUC-ROC for classification; MAE, MSE, RMSE, and R² for regression.

Q3. Explain logistic regression. Why is it called regression if it does classification?
Logistic regression applies a sigmoid function to a linear combination of features, squashing the output to a probability between 0 and 1. It is called “regression” historically because it models the log-odds as a linear regression. The sigmoid σ(z) = 1/(1 + e^-z) maps any real number to (0,1), which we interpret as the probability of the positive class. We then apply a threshold (default 0.5) to convert probability to a class label. Logistic regression is fast, interpretable (coefficients are log-odds ratios), and performs surprisingly well on linearly separable data.

Q4. What is the difference between a parametric and non-parametric model?
Parametric models have a fixed number of parameters regardless of training data size. Once trained, they summarise all learning in those parameters. Examples: linear regression (weights), logistic regression, naive Bayes, neural networks. They are faster at inference and require less memory. Non-parametric models grow with the data — their complexity is not fixed in advance. Examples: K-nearest neighbours (stores all training data), kernel SVM, decision trees (depth can grow unboundedly), Gaussian processes. Non-parametric models are more flexible but slower at inference and require more memory.

Q5. What is overfitting and underfitting? How do you detect and fix each?
Overfitting: the model memorises the training data, capturing noise rather than the true signal. It has low training error but high test error. Detect with a large gap between training and validation accuracy. Fix by: adding regularisation (L1/L2/dropout), reducing model complexity, adding more training data, using cross-validation, or applying early stopping. Underfitting: the model is too simple to capture the underlying pattern. It has high training AND test error. Fix by: using a more complex model, adding more features, reducing regularisation, or training longer.

Q6. What is cross-validation and why is it important?
Cross-validation estimates a model’s generalisation performance by repeatedly splitting data into training and validation sets and averaging results. K-fold CV splits data into K equal folds, trains on K-1 folds, validates on 1, and rotates K times. It gives a more reliable estimate of test performance than a single train/validation split because it uses all data for both training and validation. Stratified K-fold preserves class proportions in each fold — essential for imbalanced datasets. Time-series cross-validation must respect temporal order: always validate on data that comes after training data.

Q7. What is regularisation and what are L1, L2, and Elastic Net?
Regularisation adds a penalty term to the loss function to discourage complex models and prevent overfitting. L1 regularisation (Lasso) adds the sum of absolute coefficient values: Loss + λΣ|wᵢ|. It drives some coefficients to exactly zero, performing automatic feature selection — useful when many features are irrelevant. L2 regularisation (Ridge) adds the sum of squared coefficients: Loss + λΣwᵢ². It shrinks all coefficients toward zero without zeroing them — useful when most features are relevant. Elastic Net combines both: Loss + λ₁Σ|wᵢ| + λ₂Σwᵢ². The hyperparameter λ controls regularisation strength — tuned via cross-validation.

Q8. What is the curse of dimensionality?
As the number of features (dimensions) increases, data becomes exponentially more sparse. In high dimensions, the concept of distance loses meaning — all points become approximately equidistant from each other. The volume of the feature space grows so fast that the training data covers it very sparsely, making generalisation much harder. Consequences: KNN fails because nearest neighbours are no longer meaningfully “near”; more data is needed to maintain the same density; many algorithms slow down dramatically. Solutions include dimensionality reduction (PCA, t-SNE, UMAP), feature selection, and regularisation.

Model Evaluation Interview Questions

two women sitting on chair
Photo by Christina @ wocintechchat.com M on Unsplash

Q9. Explain the confusion matrix and derive precision, recall, F1, and accuracy from it.
A confusion matrix for binary classification has four cells: True Positives (TP) — correctly predicted positive; True Negatives (TN) — correctly predicted negative; False Positives (FP) — predicted positive but actually negative (Type I error); False Negatives (FN) — predicted negative but actually positive (Type II error). Accuracy = (TP+TN)/(TP+TN+FP+FN) — misleading for imbalanced classes. Precision = TP/(TP+FP) — of all predicted positives, how many are real? Recall (Sensitivity) = TP/(TP+FN) — of all actual positives, how many did we catch? F1 = 2×(Precision×Recall)/(Precision+Recall) — harmonic mean, balances both. Specificity = TN/(TN+FP) — how well we identify negatives.

Q10. When should you use precision vs recall?
This is a business decision driven by the cost of each error type. When false positives are costly, optimise for precision. Email spam detection: marking a legitimate email as spam (FP) loses important communication. When false negatives are costly, optimise for recall. Cancer screening: missing a real cancer case (FN) could be fatal. Medical diagnosis and fraud detection where missing fraud is expensive favour high recall. Content moderation where over-blocking hurts user experience favours high precision. In practice, you set a threshold based on the business cost ratio of FP to FN, then report both metrics.

Q11. What is AUC-ROC and when would you prefer it over accuracy?
The ROC (Receiver Operating Characteristic) curve plots True Positive Rate (recall) against False Positive Rate at every possible classification threshold. AUC (Area Under the Curve) summarises this as a single number: 0.5 = random classifier, 1.0 = perfect classifier. AUC is threshold-independent — it evaluates the model’s ability to rank positives above negatives. Use AUC-ROC over accuracy when: the dataset is imbalanced (a model predicting all negatives gets 99% accuracy on 1% positive-class data); you will tune the threshold later; you want a single metric that works across all operating points. Prefer precision-recall AUC when the positive class is very rare and you care more about performance on positives.

Q12. What is data leakage and how do you prevent it?
Data leakage occurs when information from outside the legitimate training window is included in model training, causing artificially high performance that collapses in production. Types: temporal leakage — using future data to predict the past (e.g., including a feature that is only known after the target event); target leakage — including features that are directly or indirectly derived from the target variable; test set leakage — fitting preprocessing (scaling, imputation) on the full dataset before splitting. Prevention: split data before any preprocessing; use pipelines that fit only on training data; carefully audit every feature for temporal validity; simulate production conditions in evaluation.

Tree-Based Models and Ensemble Methods

Q13. How does a random forest differ from a single decision tree?
A single decision tree is trained on all training data and all features at every split, making it prone to overfitting — it will memorise training noise. A random forest builds hundreds of trees, each on a bootstrap sample (random rows with replacement) of the training data, and considers only a random subset of features (typically √n_features for classification, n_features/3 for regression) at each split. The two sources of randomness reduce correlation between trees. Final predictions are made by majority vote (classification) or averaging (regression). The ensemble dramatically reduces variance compared to a single tree, achieving much lower test error for only modest additional training cost.

Q14. What is boosting and how does XGBoost implement it?
Boosting builds an ensemble sequentially: each new model focuses on the examples that previous models got wrong. AdaBoost reweights misclassified samples. Gradient boosting, which XGBoost implements, fits each new tree to the negative gradient of the loss function — the residual errors of the current ensemble. XGBoost adds several improvements over vanilla gradient boosting: second-order gradient statistics (more accurate split finding); regularisation terms (L1 and L2 on leaf weights); column and row subsampling per tree (like random forest); efficient histogram-based split finding; and tree pruning by depth rather than greedily. LightGBM further improves speed with leaf-wise (best-first) growth and Gradient-based One-Side Sampling (GOSS).

Q15. What is feature importance in tree-based models and what are its limitations?
Tree-based feature importance measures how much each feature contributes to reducing impurity (Gini or entropy for classification; MSE for regression) across all splits across all trees. High importance means the feature is used frequently and causes large impurity reductions. Three types: (1) Split count — how many times a feature is used to split. (2) Gain — total impurity reduction attributed to splits on this feature. (3) Permutation importance — how much performance drops when a feature’s values are randomly shuffled. Limitations: correlated features split importance between them, undervaluing both; high-cardinality features (many unique values) are biased toward higher importance in split-count methods; importance is global, not per-prediction — use SHAP for per-prediction explanations.

Neural Networks and Deep Learning

an abstract image of a sphere with dots and lines
Photo by Growtika on Unsplash

Q16. Explain backpropagation in plain English.
Backpropagation is the algorithm that trains neural networks by computing how much each weight contributed to the error. Forward pass: input flows through layers, producing a prediction. Loss function computes the error. Backward pass: the chain rule of calculus propagates the error gradient backward through every layer, computing ∂Loss/∂w for each weight. Gradient descent then updates each weight: w = w – α × ∂Loss/∂w. This repeats over many batches and epochs until loss converges. The key insight is that the chain rule allows efficient computation of gradients layer by layer, from output to input, making training millions of parameters feasible.

Q17. What is vanishing gradient and how is it solved?
In deep networks, gradients are multiplied together as they propagate backward through layers. If activations have derivatives less than 1 (like sigmoid: max derivative 0.25), gradients shrink exponentially with depth. Early layers receive nearly zero gradient and learn extremely slowly or not at all — the vanishing gradient problem. Solutions: (1) ReLU activation (max(0,x)) — gradient is 1 for positive inputs, never shrinks due to activation. (2) Batch normalisation — normalises layer inputs, keeping activations in healthy ranges. (3) Residual connections (ResNet) — skip connections add the input directly to the output, creating gradient highways that bypass many layers. (4) Careful weight initialisation — Xavier/He initialisation keeps activation variance stable across layers.

Q18. What is the difference between CNN and RNN, and when would you use each?
CNNs (Convolutional Neural Networks) use learnable filters that slide across spatial dimensions, capturing local patterns invariant to position. They excel at images, audio spectrograms, and any data with spatial or temporal locality. RNNs (Recurrent Neural Networks) process sequences step by step, maintaining a hidden state that summarises past inputs. They are designed for variable-length sequential data where order matters. Use CNNs for image classification, object detection, image segmentation, and text classification when order is less important. Use RNNs (or Transformers, which have largely replaced them) for time series forecasting, language modelling, machine translation, and speech recognition. LSTMs and GRUs solve the vanishing gradient problem in plain RNNs for long sequences.

Q19. What is transfer learning and when should you use it?
Transfer learning takes a model pretrained on a large dataset and fine-tunes it on a smaller domain-specific dataset. The pretrained model has already learned general features — for images: edges, textures, shapes; for text: grammar, semantics, world knowledge — that transfer to new tasks. Use transfer learning when: you have limited labelled data (fine-tuning beats training from scratch with under 10,000 examples); computation budget is limited; the domains are related (ImageNet → medical imaging, Wikipedia text → document classification). Approaches: feature extraction (freeze all pretrained layers, only train a new classification head) or fine-tuning (unfreeze some or all pretrained layers, train with a small learning rate). In NLP, BERT, GPT, and their variants are fine-tuned for virtually every task.

Unsupervised Learning

Q20. What is the difference between K-Means and DBSCAN clustering?
K-Means requires you to specify K (number of clusters) in advance, assigns every point to exactly one cluster, assumes clusters are roughly spherical and similarly sized, minimises within-cluster variance, and scales to large datasets efficiently. DBSCAN requires no K — it discovers the number of clusters automatically. It finds clusters of arbitrary shape by grouping points that are densely connected (within radius ε of at least min_samples neighbours), and labels low-density points as noise/outliers. Use K-Means for compact, well-separated, spherical clusters in large datasets. Use DBSCAN when clusters have arbitrary shapes, when you want automatic outlier detection, or when you genuinely do not know K.

Q21. Explain PCA. What does it actually do?
PCA (Principal Component Analysis) finds the directions of maximum variance in high-dimensional data and projects it onto a lower-dimensional space defined by those directions. Mathematically, it computes the eigenvectors of the covariance matrix — the principal components — and ranks them by their eigenvalues (variance explained). The first principal component is the direction of greatest variance; the second is orthogonal to the first and explains the most remaining variance, and so on. By keeping only the top k components, you retain the most information in fewer dimensions. Applications: visualisation (2-3 components), noise reduction (low-variance components are often noise), preprocessing before clustering or classification, and face recognition (eigenfaces). Limitation: PCA captures linear relationships only; use t-SNE or UMAP for non-linear dimensionality reduction.

Practical and System Design Questions

Q22. How do you handle imbalanced datasets?
First, choose the right evaluation metric — accuracy is meaningless for imbalanced data; use precision, recall, F1, or AUC-ROC. Then try these techniques in order of complexity: (1) Class weights — set class_weight=’balanced’ in sklearn or scale_pos_weight in XGBoost. This is free and often sufficient. (2) Resampling — oversample the minority class (SMOTE: Synthetic Minority Oversampling Technique, which creates synthetic samples by interpolating between minority-class neighbours) or undersample the majority (random or informed). (3) Threshold tuning — adjust the classification threshold based on your precision-recall trade-off requirement. (4) Anomaly detection framing — treat the minority class as anomalies when it is below 1%.

Q23. A model performs well in development but poorly in production. What do you investigate?
This is one of the most important practical questions. Investigate in this order: (1) Data distribution shift — are production inputs distributed differently than training data? Check feature statistics over time. (2) Target distribution shift (concept drift) — has the relationship between features and target changed? Monitor prediction distributions and real outcomes when available. (3) Data pipeline bugs — are features being computed differently in training vs production? Check for missing values that were imputed differently, date fields computed relative to different reference dates, or features not available at prediction time. (4) Training-serving skew — is the preprocessing pipeline identical? (5) Data leakage in training — were features used that would not be available at inference time? (6) Sample selection bias — was the training data representative of the production population?

Q24. What is feature engineering and what are the most impactful techniques?
Feature engineering is the process of using domain knowledge to create, transform, or select features that make patterns easier for a model to learn. It is often the highest-leverage activity in applied ML. High-impact techniques: (1) Interaction features — multiply two features to capture their joint effect. (2) Polynomial features — add squares and cubes of numeric features to capture non-linearity. (3) Target encoding — replace a categorical value with the mean target value for that category (with cross-validation to prevent leakage). (4) Log transforms — compress skewed distributions (prices, counts) to make them more normal. (5) Date/time features — extract day of week, hour, month, days since last event, is_weekend, is_holiday. (6) Text features — TF-IDF, word embeddings, character n-grams. Good feature engineering regularly outperforms model selection and hyperparameter tuning combined.

Q25–30 (Rapid fire):

Q25. What is the No Free Lunch theorem? No single algorithm performs best on all problems. Every algorithm makes assumptions; the best model for any task depends on the specific structure of that task’s data distribution. This is why we always try multiple algorithms.

Q26. What is a hyperparameter vs a parameter? Parameters are learned from data during training (weights, biases). Hyperparameters are set before training and control the learning process (learning rate, number of layers, regularisation strength). Tune hyperparameters via grid search, random search, or Bayesian optimisation (Optuna).

Q27. What is batch gradient descent vs stochastic vs mini-batch? Batch GD computes the gradient on all training data per step — precise but slow. SGD computes gradient on one sample per step — noisy but fast, good regularisation effect. Mini-batch GD (most common in practice) uses a small batch (16-256) — balances noise and efficiency, enables GPU parallelism.

Q28. What is the VC dimension? The Vapnik-Chervonenkis dimension is the maximum number of points that a classifier can shatter (correctly classify in every possible labelling). It measures model capacity. A linear classifier in 2D has VC dimension 3. Higher VC dimension = more complex model = more data needed to generalise well.

Q29. What is multi-task learning? Training a single model to perform multiple related tasks simultaneously, sharing representations across tasks. Often improves performance on all tasks because the model learns more robust features that generalise across tasks. Example: a model that simultaneously predicts churn, lifetime value, and next purchase category.

Q30. How does SMOTE work? For each minority-class sample, SMOTE finds its k nearest minority-class neighbours and creates synthetic samples by interpolating: new_sample = sample + λ × (neighbour – sample), where λ ∈ [0,1]. This creates realistic synthetic minority samples in feature space rather than duplicating existing ones, avoiding simple oversampling’s overfitting risk.

Sample Code: Model Evaluation Pipeline

from sklearn.model_selection import StratifiedKFold, cross_validate
from sklearn.metrics import make_scorer, f1_score, roc_auc_score
from sklearn.ensemble import GradientBoostingClassifier
import numpy as np

scoring = {
    'auc':       'roc_auc',
    'f1':        make_scorer(f1_score),
    'precision': 'precision',
    'recall':    'recall'
}

cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
model = GradientBoostingClassifier(n_estimators=200, max_depth=4,
                                    learning_rate=0.05, random_state=42)

results = cross_validate(model, X, y, cv=cv, scoring=scoring, n_jobs=-1)
for metric, scores in results.items():
    if metric.startswith('test_'):
        name = metric.replace('test_', '')
        print(f'{name:12s}: {scores.mean():.4f} ± {scores.std():.4f}')

How to Prepare for an ML Interview

The best preparation combines three tracks. First, build conceptual depth — read Hands-On Machine Learning (Géron), The Elements of Statistical Learning, and the original papers for key algorithms. Second, practice implementation — code linear regression, logistic regression, and k-means from scratch in numpy. This reveals understanding gaps that memorised answers hide. Third, study system design — know how to design a recommendation system, a churn prediction model, a fraud detection system end to end. Interviewers assess not just whether you know the algorithms but whether you can think through the business problem, data collection, model selection, evaluation, and deployment as a coherent system.

Conclusion

ML interviews reward depth over breadth. Know the fundamental algorithms thoroughly — not just their names but how they learn, what assumptions they make, when they fail, and how to fix those failures. Understand model evaluation metrics and when each is appropriate. Practice explaining your reasoning clearly, because interviewers are evaluating how you think as much as what you know. These 30 questions cover the core of what virtually every ML interview will test in 2026.

Leave feedback about this

  • Rating

Durgesh Kekare
Durgesh Kekarehttps://www.dataexpertise.in
Durgesh Kekare is a data science educator and founder of DataExpertise.in. With expertise in Python, machine learning, and analytics, he helps 10,000+ learners break into data careers.

Latest Posts

List of Categories