Machine Learning Interview Questions
Core machine learning questions on algorithms, evaluation, overfitting and deployment.
Bias is error from overly simple assumptions, variance is error from sensitivity to the training data. Simple models tend to underfit with high bias, complex models overfit with high variance. The goal is the level of complexity that minimises error on unseen data.
Overfitting is when a model learns noise in the training data and performs worse on new data. Prevent it with more data, simpler models, regularisation, early stopping, dropout for neural networks and cross-validation to measure real performance.
If 99 percent of cases are negative, a model that always predicts negative scores 99 percent accuracy while being useless. Use precision, recall, F1, precision-recall curves or cost-based metrics suited to the problem.
Precision is the share of predicted positives that are correct. Recall is the share of actual positives that are found. Favour recall when missing a case is costly, such as disease screening, and precision when false alarms are costly, such as blocking legitimate payments.
It splits the data into several folds, trains on some and validates on the rest, rotating through all folds. It gives a more reliable performance estimate than one split, especially with limited data. For time series, use forward-chaining splits to avoid leaking the future.
Random forests train many trees independently on random samples and average them, which reduces variance. Gradient boosting trains trees sequentially, each correcting the errors of the previous ones, which usually gives higher accuracy but needs more careful tuning.
Regularisation adds a penalty on model complexity to the loss. L1 penalises absolute weights and can drive some to zero, giving sparse models. L2 penalises squared weights and shrinks them smoothly without removing features.
Leakage is when information unavailable at prediction time enters training, giving unrealistically good results. Examples are scaling using the full dataset before splitting, features built from future data and duplicate records across train and test.
First understand why they are missing. Options include removing rows or columns, imputing with mean, median or model-based estimates, and adding a missing indicator. Fit imputation only on training data to avoid leakage.
In deep networks, gradients can shrink as they flow backwards, so early layers learn very slowly. Mitigations include ReLU-type activations, careful weight initialisation, batch normalisation and residual connections.
Monitor input distributions, prediction distributions and, when labels arrive, actual performance. Alert when they shift from the training baseline, then retrain on fresh data or investigate upstream changes. Keep versioned data and models so you can roll back.
Refactor into tested code, version the data, features and model, build a reproducible training pipeline, package for serving with a clear latency budget and add monitoring and rollback. Validate with a shadow or staged rollout before sending full traffic.