Welcome! These 50 questions are drawn from real interviews at Amazon, Google, Stripe, and fintech firms in Kenya and India. Each has a detailed answer grounded in the concepts you've learned in this track. Click any question to reveal the answer.
1. Statistics & Probability (10 questions)
Mean is the arithmetic average of all values. Median is the middle value when sorted. Mode is the most frequent value. Use median for skewed data (outliers don't shift it), mean for symmetric data, and mode for categorical data or to find the most common category.
A bell-shaped, symmetric distribution defined by mean and standard deviation. Most values cluster around the mean; 68% fall within 1 SD, 95% within 2 SD, 99.7% within 3 SD. Many natural phenomena (heights, test scores, errors) approximate normal distributions, making it foundational for hypothesis testing.
A p-value is the probability of observing your test result (or more extreme) if the null hypothesis is true. Low p-value (< 0.05) means the result is unlikely under null, so we reject it. It's not the probability the hypothesis is true—it's the probability of the data given the hypothesis.
CLT states that the distribution of sample means approaches a normal distribution as sample size increases, regardless of the underlying distribution shape. This is why we can use normal-based statistics (t-tests, confidence intervals) even when the population isn't normal—a foundation of statistical inference.
Correlation measures the strength of a linear relationship between two variables. Causation means one causes the other. High correlation does not imply causation. Example: ice cream sales and drowning deaths are correlated (both increase in summer), but ice cream doesn't cause drowning. You need experiments or causal reasoning to prove causation.
Type I error: rejecting the null hypothesis when it's true (false positive). Type II error: failing to reject the null when it's false (false negative). Significance level alpha controls Type I; power (1 - beta) controls Type II. In medical testing, Type I means a healthy person is flagged sick; Type II means a sick person is cleared.
Calculate the correlation matrix and look for high pairwise correlations (> 0.8). Compute the Variance Inflation Factor (VIF) for each feature; VIF > 5-10 signals multicollinearity. Check the condition number of the design matrix (high values = collinearity). In regression output, large coefficient standard errors despite significant overall fit also hint at collinearity.
Frequentist: probability is the long-run frequency of events; parameters are fixed. Use hypothesis tests and confidence intervals. Bayesian: probability is a degree of belief; incorporate prior knowledge and update with data via Bayes' theorem. Bayesians produce credible intervals and posterior distributions. Frequentist is standard in ML; Bayesian is interpretable and can leverage domain expertise.
Use non-parametric tests (e.g., Mann-Whitney U, Kruskal-Wallis) when data violates assumptions of parametric tests: non-normal distributions, small samples, ordinal data, or heavy outliers. They test medians and ranks instead of means. Downside: lower power (harder to detect true effects) and less interpretable. Always check normality before choosing.
Expected squared error = Bias^2 + Variance + Irreducible Error. Bias is how far the model's prediction is from the truth on average. Variance is how much the model's prediction changes across different training sets. Simple models (high bias, low variance) underfit. Complex models (low bias, high variance) overfit. The optimal model balances both to minimize total error.
2. Regression & Classification (10 questions)
Regression predicts continuous values (house price, temperature). Classification predicts discrete categories (spam/not spam, churn/no churn). Regression uses MSE or MAE as loss. Classification uses cross-entropy or log loss. Metrics differ: R^2 for regression; accuracy, precision, recall for classification.
Linear regression fits a line y = mx + b through data by minimizing squared residuals (MSE). In matrix form: y = Xw + noise. Solve for w using the normal equation w = (X^T X)^-1 X^T y, or gradient descent if X^T X is singular. The coefficient w tells you: per-unit change in feature → w-unit change in target.
Accuracy is bad when classes are imbalanced. If 95% of data is negative, a classifier that always predicts negative gets 95% accuracy but is useless. Use precision, recall, F1 score, or ROC-AUC instead. Precision = true positives / predicted positives; recall = true positives / actual positives. Choose based on the cost of false positives vs false negatives.
ROC curve plots True Positive Rate (recall) vs False Positive Rate as you vary the classification threshold. AUC (Area Under Curve) is the probability the model ranks a random positive higher than a random negative. AUC = 0.5 means random guessing. AUC = 1.0 means perfect classification. AUC handles imbalanced data better than accuracy.
Regularization adds a penalty term to the loss function to discourage large weights: L1 (lasso) = lambda * |w|, L2 (ridge) = lambda * w^2. L1 shrinks some weights to zero (feature selection). L2 shrinks all weights proportionally (avoids extremes). Regularization prevents overfitting by reducing model complexity and improving generalization to new data.
A single tree is prone to overfitting: it memorizes training noise. Random Forest trains many trees on random subsets of data and features, then averages predictions. This ensemble reduces variance without increasing bias much (bias-variance tradeoff). RF also handles missing values and non-linear relationships well, and provides feature importance rankings.
Loss L = (1/2) * sum((y_i - w^T x_i)^2). Gradient dL/dw = -(sum(x_i * (y_i - y_pred_i))). Update rule: w := w + eta * sum(x_i * residual_i), where eta is learning rate. Each iteration, move in the direction that reduces loss. For batch gradient descent, sum over all samples; for SGD, use one sample at a time.
Random Forest grows independent trees in parallel, each on random subsets. XGBoost grows trees sequentially: each new tree corrects errors of previous trees (gradient boosting). XGBoost uses a loss function + regularization term, shrinkage (learning rate), and column subsampling. Result: XGBoost converges faster and often outperforms RF, but is slower to train and harder to tune.
Without math: if data isn't linearly separable in 2D, the kernel trick transforms it into a higher-dimensional space where it becomes separable. No need to compute coordinates explicitly. With math: instead of computing phi(x_i)^T phi(x_j) in the high-dim space, use kernel K(x_i, x_j) = . Examples: RBF kernel K(x, y) = exp(-gamma * ||x-y||^2), polynomial K(x, y) = (x^T y + c)^d.
Not necessarily. If only 0.1% of transactions are fraudulent, a model that classifies everything as legitimate gets 99.9% accuracy but catches zero fraud. Check: fraud rate, precision (of flagged frauds, how many are real?), recall (of actual frauds, how many do we catch?), and business cost (false positive costs you service revenue; false negative costs fraud). Choose threshold based on these costs.
3. Unsupervised Learning (10 questions)
Unsupervised learning finds structure in unlabeled data without a target variable. K-Means clusters customers by spending. PCA reduces dimensions. Anomaly detection flags outliers. No ground truth to train against, so you define success: minimize within-cluster variance (K-Means), maximize explained variance (PCA), or find rare observations (anomaly detection).
K-Means iterates: (1) Initialize k random centroids. (2) Assign each point to the nearest centroid. (3) Recompute centroid as the mean of assigned points. (4) Repeat 2-3 until convergence. Goal: minimize within-cluster variance (sum of squared distances from points to centroids). Converges in a few iterations but can get stuck in local minima; run multiple times with different seeds.
Elbow method: plot inertia (within-cluster variance) vs k. Choose k where inertia "elbows" (diminishing returns kick in). Silhouette score: for each k, compute average silhouette coefficient (-1 to 1; higher is better). Gap statistic: compare inertia to a null model. Domain knowledge: if you know you have 3 customer segments, use k=3. No perfect method; try multiple and validate with business insight.
DBSCAN finds clusters of arbitrary shape, tolerates noise (outliers), and doesn't require specifying k in advance. K-Means assumes spherical clusters and requires k. Use DBSCAN when: clusters are non-spherical, density varies, or you have many outliers. Downside: DBSCAN has hyperparameters (epsilon, min_samples) that are sensitive to data scale. K-Means is simpler and faster.
PCA (Principal Component Analysis) rotates the data to find directions of maximum variance. The first component captures the most variance, the second captures the most remaining variance, etc. Use PCA to reduce dimensions: retain 95% of variance but drop 50% of features. This speeds up training, reduces noise, and helps visualize high-dimensional data. Downside: principal components are linear combinations of original features—hard to interpret.
Silhouette score measures how similar a point is to its own cluster vs other clusters. For each point: a = avg distance to points in same cluster, b = avg distance to points in nearest other cluster. Silhouette = (b - a) / max(a, b), ranging from -1 to 1. Values close to 1 = well-clustered, 0 = overlapping clusters, -1 = wrong cluster. Average silhouette score across all points indicates overall clustering quality.
K-Means will produce poor clusters if data is non-spherical (e.g., crescent moons, rings). Solutions: (1) Use DBSCAN or spectral clustering for non-convex shapes. (2) Transform features (e.g., log, polynomial features) to make clusters more spherical. (3) Use Gaussian Mixture Models (GMM) which allow clusters to have different shapes and sizes. (4) Visualize with t-SNE or UMAP to inspect true structure.
It depends. If original data has 100 dimensions and you need 2D visualization, 18% is reasonable—you've compressed 100x with interpretable loss. But if 18% means you're losing 82% of signal, that's not useful for downstream tasks (e.g., classification). Check: How many components do you need to retain 90-95% variance? Is 2D a hard requirement (visualization) or a preference (speed)? If speed, use more components. If visualization, accept the 18%.
(1) Load data: customer ID, RFM (recency, frequency, monetary), demographics. (2) Preprocessing: fill missing, scale features (K-Means is distance-based). (3) Dimensionality: PCA to reduce from 50 features to 10-15 if needed. (4) Clustering: K-Means with k=3-5 (elbow method), or hierarchical for interpretability. (5) Profile segments: compute segment statistics (avg spend, purchase frequency). (6) Validate: silhouette score, business alignment. (7) Deploy: assign new customers to nearest centroid in batch monthly.
Internal validation: silhouette score, Davies-Bouldin index (lower = better), calinski-harabasz score (higher = better). Stability validation: re-cluster on bootstrap samples; check if cluster assignments are consistent. External validation (if some labels exist): purity, NMI, adjusted rand index. Domain validation: do segments align with business reality? Interview customers in each cluster to confirm they're homogeneous.
4. Feature Engineering & Data Prep (10 questions)
Models like KNN, SVM, and neural networks use distances or gradients. Unscaled features with larger ranges dominate (age 20-80 vs income 20k-100k). Scaling puts features on equal footing. StandardScaler (mean=0, std=1) is standard for distance-based models. Some models (tree-based: RF, XGBoost) are scale-invariant, so scaling is optional but doesn't hurt.
First, check missingness pattern. Random missing (MCAR) = safe to fill with median/mode. Systematic missing (MNAR) = risky; consider a separate "missing" category. Strategies: (1) Drop rows if < 5% missing. (2) Fill numeric with median (robust) or mean. (3) Fill categorical with mode or "Unknown". (4) KNN imputation using similar rows. (5) Model-based imputation (MICE). Avoid listwise deletion for > 5% missing.
Target encoding replaces each category with the mean target value for that category (e.g., male customers have 22% churn, so encode "Male" as 0.22). It's powerful because it captures category-target relationship directly. Risk: data leakage. If you compute target encoding on the entire dataset, the model learns the target distribution from training data, inflating validation performance. Fix: compute encoding on train set only, apply to test.
One-hot encoding 500 categories creates 500 columns = memory bloat + curse of dimensionality. Options: (1) Group rare categories into "Other" (keep top 50, rest as other). (2) Target encoding (category → avg target). (3) Hashing (category → hash mod k, where k=50). (4) Embeddings (learn k-dim representation). (5) Ordinal encoding if categories have natural order. Choose based on model type and data size.
Stratification ensures train and test have the same class distribution as the original data. Random split might leave rare classes in one set. Example: 22.8% churn in original. Without stratify, test might have 20% churn (by chance), giving a skewed estimate of model performance. With stratify=y, both train and test have ~22.8% churn, giving honest estimates. Essential for imbalanced datasets.
Data leakage: information from test set leaks into training, inflating model performance. Example 1: scale entire dataset before split (train learns statistics from test). Example 2: use target encoding on full data before split (test's target distribution leaks into features). Example 3: include "months_since_event" when predicting the event (information after the event). Fix: always split first, then preprocess. Fit transformers on train, apply to test.
Methods: (1) Univariate: score each feature vs target independently (chi2 for classification, f_regression for regression), select top k. (2) Recursive feature elimination (RFE): train model, drop least important feature, retrain, repeat. (3) L1 regularization (lasso): non-zero weights are important. (4) Tree importance: train tree, extract feature_importances_. (5) Correlation: drop features highly correlated with others. Combine multiple methods; domain knowledge matters.
(1) Domain features: price_per_sqft = price / area, age = year_sold - year_built. (2) Interactions: large_lot * good_location (both amplify value). (3) Polynomial: sqrt(area) often more predictive than area (diminishing returns). (4) Temporal: seasonality, month effects. (5) Geographic: binned zip codes, distance to transit. (6) Categorical: encode high-cardinality zip as target encoding (avg price per zip). (7) Selection: drop features with low variance, high correlation with others. (8) Validation: check feature importance; features should align with domain knowledge.
SMOTE: oversamples minority class by creating synthetic samples (interpolate between neighbors). Class weights: penalize minority class errors more during training. SMOTE pros: generates new data, reduces data imbalance. Cons: can create unrealistic samples, memory intensive. Class weights pros: simple, no new data. Cons: may not help if minority class is very rare. Use class weights first (faster); if still poor minority recall, add SMOTE. Always validate on imbalanced test set, never on balanced training data.
Common issues: (1) Data leakage: dev model uses future information. (2) Distribution shift: production data differs from training (different user base, system changes). (3) Preprocessing mismatch: dev scales globally; production scales per-batch. (4) Feature unavailability: a feature doesn't exist in production. (5) Dependency errors: upstream data pipeline changed. (6) Sampling bias: dev test set unrepresentative. Diagnosis: monitor prediction distribution, feature distributions, prediction errors. Re-validate on recent data. Retrain regularly.
5. ML System Design (10 questions)
Pipeline: (1) Data collection (raw logs, databases). (2) Preprocessing (cleaning, encoding, scaling). (3) Feature engineering (create informative features). (4) Model training (fit algorithm on train data). (5) Evaluation (test on held-out set). (6) Deployment (serve predictions). (7) Monitoring (track performance drift). (8) Feedback (retrain on new data). End-to-end, iterative process. Most time is spent on steps 1-3, not training.
Cross-validation (e.g., k-fold) splits data into k folds, trains on k-1 and tests on 1, repeating k times. Gives a more stable estimate of model performance than a single train/test split. Reduces variance in performance estimate. Useful when data is limited (small k = larger folds, more training) or when you want robust hyperparameter tuning. Downside: k times slower than single split.
GridSearchCV exhaustively tries all parameter combinations (e.g., learning_rate in [0.01, 0.1, 1], depth in [3, 5, 7] = 9 combinations). Guarantees finding best in grid but slow if many hyperparameters. RandomizedSearchCV randomly samples parameter combinations (e.g., 100 random samples). Faster, good for large search spaces, often finds near-optimal in less time. Use Grid for small search spaces (< 5^2), Random for large spaces.
Avoid jargon. Lead with business impact: "This model identifies customers likely to churn next month. We can proactively offer them a discount, reducing churn by 15% and saving $500k annually." Then explain how: "The model learns patterns from past customers: those who contact support twice are 5x more likely to churn. We use these patterns on current customers." Show metrics: "Of customers we flag, 70% actually churn (precision). We catch 80% of future churners (recall)." Use visuals: feature importance chart, confusion matrix.
sklearn Pipeline chains preprocessing and model steps: Pipeline([('scaler', StandardScaler()), ('model', LogisticRegression())]). Benefits: (1) Prevents data leakage (scaler fit only on train). (2) Single object to save/load (no separate scaler + model). (3) Automatic hyperparameter tuning (GridSearchCV works on pipeline steps). (4) Cleaner code. (5) Reproducibility. Always use pipelines in production; avoid ad-hoc preprocessing scripts.
F1 = 0.44 is low (perfect = 1.0, random = 0.5 for balanced data). Decision depends on: (1) Baseline: what's the current human performance or rule-based model? (2) Cost: false positive cost vs false negative cost. (3) Use case: if catching 1 fraud is worth 100 false alarms, low F1 might be okay if recall is high. Compute precision, recall separately. Is it imbalanced? Inspect predictions: does model predict only majority class? If F1 is truly too low, collect more data, engineer better features, or try different algorithms.
(1) Data: daily ETL from CRM/billing (customer RFM, demographics, support tickets). (2) Features: engineer churny signals (e.g., declining usage, support issues). (3) Labels: 30-day forward churn definition. (4) Train: monthly on 2 years history, 80/20 stratified split, cross-validate. (5) Model: logistic regression (interpretable) or XGBoost (higher AUC). (6) Thresholding: choose threshold to target 50% recall (catch half of future churners). (7) Serving: batch predict monthly, store scores in database, expose via API. (8) Monitoring: track AUC, precision, recall weekly. Alert if AUC drops > 5%. (9) Feedback: log actual churn, retrain monthly. (10) Action: marketing team runs retention campaigns on high-risk customers.
Two types: (1) Data drift: feature distributions change (e.g., user age distribution shifts). (2) Label drift: target distribution changes (churn rate rises). Monitor: (1) Input distributions: track mean/std of features daily. (2) Prediction distribution: is the model still predicting a range, or mostly one class? (3) Performance metrics: re-evaluate on recent data (use labels when available). (4) Prediction-actuality: log predictions and actual outcomes; compare. Triggers for retraining: data drift detected, AUC drops > 5%, or on schedule (monthly). Automate with MLOps tools (Airflow, Kubeflow).
(1) Define metric: e.g., click-through rate, conversion rate, revenue-per-user. (2) Sample size: compute N needed to detect 5% lift with 80% power (use power analysis). (3) Split traffic: 50% control (old model), 50% treatment (new model) randomly per user. (4) Randomization unit: per user (not per request, which can bias). (5) Duration: run for >= 1 week to capture weekly seasonality. (6) Analysis: t-test to compare metric means. (7) Guardrails: monitor latency, error rates to catch bugs. (8) Decision: if new model wins on primary metric and doesn't break guardrails, launch. Otherwise, investigate and iterate.
Nested CV: outer loop evaluates model, inner loop tunes hyperparameters. Prevents selection bias: if you tune hyperparameters on the same data used for evaluation, you overfit hyperparameters. Outer loop: split into k folds. Inner loop (on train fold): GridSearchCV to pick best hyperparameters. Evaluate on test fold. Repeat k times. Final score = average across outer folds. Expensive (k * m training runs), but gives unbiased performance estimate. Use when you have limited data and want honest evaluation.
Africa & India's Best AI Academy
Ready to ace your interview?
Join the Best AI Program: The AI-Era Analyst — 5 months, fully online, with placement assistance. Week 1 is free.
Explore The AI-Era Analyst →