What is the bias-variance tradeoff?
Bias is error from oversimplifying assumptions (underfitting). Variance is error from sensitivity to small data fluctuations (overfitting). High bias: model too simple, misses patterns. High variance: model too complex, memorizes noise. The tradeoff: reducing bias typically increases variance. Optimal models minimize total error = bias² + variance + irreducible noise. In practice: regularization (L1/L2), dropout, and cross-validation help find the right balance.
What is cross-validation and when should you use k-fold vs stratified k-fold?
Cross-validation evaluates model performance by splitting data into k folds, training on k-1, testing on 1, and averaging results. K-fold: use for regression and balanced classification. Stratified k-fold: maintains class distribution in each fold — use for imbalanced classification (e.g., 95% negative, 5% positive). Time series: always use TimeSeriesSplit to prevent data leakage (future data in training set).
Explain the difference between precision, recall, and F1-score.
Precision = TP/(TP+FP): of predicted positives, how many are correct? Recall = TP/(TP+FN): of actual positives, how many did we catch? F1 = harmonic mean of precision and recall. Choose based on cost: high precision needed when false positives are costly (spam detection — don't flag real emails). High recall needed when false negatives are costly (cancer screening — don't miss cases). F1 balances both.
How does gradient descent work and what are its variants?
Gradient descent minimizes loss by iteratively moving in the direction of the negative gradient. Variants: (1) Batch GD — uses entire dataset per step, slow but stable, (2) SGD — one sample per step, noisy but fast, (3) Mini-batch GD — subset per step, best of both. Modern variants: Adam (adaptive learning rates per parameter), AdamW (Adam + weight decay), RMSprop. Adam is the default choice for most deep learning and fine-tuning tasks.
What is regularization and explain L1 vs L2?
Regularization adds a penalty term to the loss function to prevent overfitting. L1 (Lasso): penalty = λ|w|, produces sparse weights (some weights become exactly 0) — good for feature selection. L2 (Ridge): penalty = λw², shrinks weights toward zero but rarely to exactly 0 — good general regularization. ElasticNet combines both. For neural networks, use dropout and weight decay (L2) instead of explicit regularization.
Unlock 3,000+ Interview Questions
Get full access to all interview questions with detailed answers, explanations, and real company context
Unlock Full Access →