AI / ML
Top AI & Machine Learning Engineer Interview Questions 2026
Prep tips for AI / ML Engineer interviews
- Explain your reasoning for model choices — interviewers care more about trade-off thinking than perfect answers
- Know bias-variance tradeoff, overfitting, regularisation cold — these appear in almost every ML loop
- For system design, think about data pipelines, feature stores, model serving, and monitoring
- Be ready to code: numpy array ops, gradient descent from scratch, a simple neural net forward pass
- Bias is error from overly simplistic assumptions (underfitting); variance is error from sensitivity to small training data fluctuations (overfitting). A linear model fit to non-linear data has high bias; a deep decision tree memorising training noise has high variance. The goal is finding the sweet spot where total error — bias² + variance + irreducible noise — is minimised. Techniques like cross-validation help you locate that point for a given model family.
- Gradient descent minimises a loss function by iteratively updating parameters in the direction of the negative gradient: θ = θ − α∇L. Batch GD computes gradients over the entire dataset — stable but slow and memory-intensive. Stochastic GD (SGD) updates per sample — fast and can escape local minima but noisy. Mini-batch GD is the standard in practice: updates on small batches (32–256 samples), balancing stability and speed, and enabling vectorised GPU computation.
- Regularisation adds a penalty term to the loss function to discourage large weights and reduce overfitting. L2 (Ridge) adds λ∑w² — it shrinks all weights smoothly toward zero, keeping all features. L1 (Lasso) adds λ∑|w| — it can drive weights to exactly zero, producing sparse models and performing implicit feature selection. Use L1 when you suspect many irrelevant features; L2 when all features are expected to contribute.
- Randomly initialise K centroids. Repeat: (1) assign each point to the nearest centroid using Euclidean distance; (2) recompute each centroid as the mean of its assigned points. Stop when centroids no longer move or a max iteration limit is reached. In numpy: use broadcasting for distance computation —
np.linalg.norm(X[:, None] - centroids[None, :], axis=2). K-means is sensitive to initialisation — use k-means++ (initialise centroids with probability proportional to distance) in production. - Split into offline and online layers. Offline: train collaborative filtering (matrix factorisation) and content-based models on historical interactions; store pre-computed user/item embeddings in a vector database (e.g. Faiss, Pinecone). Online: at request time, retrieve top-N candidates from the vector DB using ANN search, then re-rank with a lightweight model (XGBoost or a small NN) incorporating real-time signals (current session, inventory). Serve via a low-latency API (<50ms) backed by Redis for session context. Add A/B testing infrastructure and track CTR/conversion as the key metrics.
- Precision = TP/(TP+FP) — of all predicted positives, how many were actually positive. Recall = TP/(TP+FN) — of all actual positives, how many did you catch. F1 = harmonic mean of the two. Optimise precision when false positives are costly (e.g. spam filter — you don't want to block legitimate email). Optimise recall when false negatives are costly (e.g. cancer screening — missing a positive is worse than a false alarm). F1 balances both; use it when neither error type dominates.
- As the number of features grows, the volume of the feature space grows exponentially, making data increasingly sparse. Distance-based algorithms like k-NN degrade because all points become approximately equidistant in high dimensions. Models require exponentially more training data to generalise well. Mitigations include dimensionality reduction (PCA, t-SNE, autoencoders), feature selection, and regularisation.
- A feature store has two serving paths: offline (for training) and online (for inference). Offline store: a data warehouse (BigQuery, Redshift) or Delta Lake table holding historical feature values with time-travel support to prevent data leakage. Online store: a low-latency key-value store (Redis, DynamoDB) holding the latest feature values per entity (user_id, item_id). Feature computation runs via a streaming pipeline (Kafka + Flink or Spark Streaming) to keep both stores in sync. Add a feature registry with metadata, versioning, and lineage tracking. Key concerns: point-in-time correctness during training, serving latency <10ms, and feature reuse across teams.
- Random forest builds many decision trees independently using bagging (bootstrap sampling of data) and random feature subsets, then averages (regression) or majority-votes (classification) predictions. This reduces variance. Gradient boosting builds trees sequentially — each tree corrects the residual errors of the previous ensemble, reducing bias. Random forests are faster to train and more robust to overfitting; gradient boosting (XGBoost, LightGBM) generally achieves higher accuracy on tabular data but requires careful tuning of learning rate, depth, and regularisation.
- Cross-validation estimates model generalisation performance by partitioning training data into K folds, training on K-1 folds, and evaluating on the held-out fold, repeating K times and averaging the results. It prevents over-optimistic evaluation from a single train/test split and helps with hyperparameter selection without touching the test set. Stratified K-fold is used for imbalanced classification to preserve class proportions in each fold.
- Data drift occurs when the statistical distribution of input features changes from training distribution. Detect it with statistical tests: KS test for continuous features, chi-squared for categorical, or Population Stability Index (PSI). Monitor feature distributions, prediction distributions, and business metrics (CTR, conversion) continuously. Set threshold alerts. Handle drift by: (1) retraining on recent data on a schedule or triggered by drift alerts; (2) online learning for fast-moving distributions; (3) weighted sampling to down-weight old data. Always maintain a model registry with rollback capability.
- Logistic regression applies the sigmoid function to a linear combination of features: ŷ = σ(Xw + b) where σ(z) = 1/(1+e⁻ᶻ). Loss is binary cross-entropy: L = −[y log(ŷ) + (1−y)log(1−ŷ)]. Gradients: dw = (1/m) X^T(ŷ−y), db = mean(ŷ−y). Update: w -= α·dw, b -= α·db. In numpy, this is ~15 lines — be ready to write it. Add L2 regularisation by appending λw to dw.
- Use STAR format. Choose an honest example — interviewers value self-awareness over perfection. Cover: what the model was predicting, how it was evaluated offline (looked fine), what failed in production (data leakage, distribution shift, latency, edge cases), how you detected the failure, the steps you took to fix it, and what monitoring or processes you put in place afterward to prevent recurrence.
- Real-time scoring required: each transaction must be scored in <100ms. Feature engineering: user history aggregates (spend velocity, geo changes), device fingerprinting, merchant category — precomputed in a feature store. Model: gradient boosting (XGBoost/LightGBM) or a neural net; ensemble with rule engine for known fraud patterns. Serving: model behind a low-latency REST API. Labels are highly imbalanced (fraud ~0.1%) — use stratified sampling, SMOTE, or cost-sensitive learning. Offline: retrain weekly on new labelled data; champion-challenger deployment. Monitor false positive rate carefully — blocking legitimate transactions has direct revenue impact.
- Attention computes a weighted sum of values, where weights come from the similarity (dot product) between queries and keys: Attention(Q,K,V) = softmax(QKᵀ/√d_k)V. Each token attends directly to all other tokens, capturing long-range dependencies in O(1) steps — unlike RNNs which require O(n) sequential steps and suffer from vanishing gradients over long sequences. Multi-head attention runs several attention operations in parallel, each learning different relationship types. Transformers are also fully parallelisable during training, making them far more GPU-efficient than recurrent architectures.
- During backpropagation, gradients are multiplied layer by layer. If activation derivatives are consistently <1 (e.g. sigmoid/tanh), gradients shrink exponentially in deep networks, making early layers learn extremely slowly or not at all. Solutions: (1) ReLU activations — derivative is 1 for positive inputs; (2) residual connections (skip connections in ResNets) — gradients flow directly through the shortcut path; (3) batch normalisation — stabilises activations; (4) careful weight initialisation (Xavier/He).
- Several complementary strategies: (1) Resampling — oversample the minority class (SMOTE generates synthetic samples) or undersample the majority; (2) Class weights — set
class_weight='balanced'in sklearn to penalise misclassifying the minority class more; (3) Threshold tuning — adjust the classification threshold (default 0.5) using the precision-recall curve; (4) Evaluation metrics — use F1, PR-AUC, or ROC-AUC instead of accuracy, which is misleading on imbalanced data. The best approach depends on the business cost of false positives vs false negatives. - Monitoring covers three layers: (1) Infrastructure — latency, throughput, error rates; (2) Data quality — null rates, schema violations, feature drift (PSI/KS tests); (3) Model performance — prediction distribution drift, and business KPIs as proxies when ground truth labels are delayed. Alerting via PagerDuty or similar on threshold breaches. Retraining: scheduled (weekly/monthly) or triggered by drift alerts. Pipeline: new data → feature engineering → training → offline evaluation → shadow deployment → champion-challenger A/B test → promote if improvement is significant. Use MLflow or similar for experiment tracking and model registry with rollback support.
- Lead with the business outcome, not the method — "The model correctly flags 85% of fraudulent transactions while raising a false alarm only 2% of the time" is more actionable than "we achieved 0.92 AUC." Use analogies for concepts like precision/recall. Use visualisations: confusion matrices as simple tables, SHAP plots to show which factors drove a specific prediction. Invite questions and check for understanding. Tie the result back to the decision they need to make.
- Both are ensemble methods that combine multiple weak learners. Bagging (Bootstrap Aggregating) trains models in parallel on random subsets of data with replacement, then averages predictions — primarily reduces variance (e.g. Random Forest). Boosting trains models sequentially, with each model focusing on the mistakes of the previous one — primarily reduces bias (e.g. AdaBoost, XGBoost, LightGBM). Bagging is more parallelisable and less prone to overfitting; boosting typically achieves higher accuracy but requires more careful hyperparameter tuning.
Practice these questions with Cogniv
Get real-time AI answers during live mock interviews. Free to start.
Start practicing →