Interview prep
34 questions you'll actually be asked
The machine-learning, deep-learning, and LLM questions that come up again and again — each with a clear, correct answer, and a link to the lesson that teaches it properly. Read the answer, then go learn the "why".
Python, data & statistics 6
Why are NumPy arrays faster than Python lists for numeric work?
A NumPy array is a contiguous block of one dtype, so operations run as compiled, vectorised C loops over the whole array at once — no per-element Python object overhead or type checks. A list holds boxed Python objects scattered in memory and must be looped one at a time.
Learn it → NumPyWhat is data leakage and how do you prevent it?
Leakage is when information from outside the training data (often the target, or the test set) sneaks into training, giving a falsely great score that collapses in production. Prevent it by splitting first, then fitting every transform (scalers, encoders, imputers) only on the training fold — never the whole dataset.
Learn it → Feature EngineeringExplain the bias–variance tradeoff.
Bias is error from a model too simple to capture the pattern (underfitting); variance is error from a model so flexible it memorises noise (overfitting). Increasing model complexity lowers bias but raises variance — you tune for the sweet spot with validation data.
Learn it → ML FundamentalsWhat is a p-value — and what is it NOT?
It is the probability of seeing a result at least this extreme if the null hypothesis were true. It is NOT the probability the hypothesis is true, nor the size or importance of an effect. A small p-value means "surprising under the null", nothing more.
Learn it → Probability & StatisticsHow would you design an A/B test?
Define one metric and a hypothesis, randomly split users into control and variant, pick a sample size from the effect you care about and the significance/power you want, run until that size (not until it looks good), then test whether the difference is beyond what noise explains.
Learn it → Probability & StatisticsHow do you handle an imbalanced dataset?
First stop using accuracy — use precision/recall, F1, or ROC-AUC. Then options: resample (oversample the minority e.g. SMOTE, or undersample the majority), reweight the loss toward the minority class, or adjust the decision threshold. Match the choice to what a false positive vs false negative actually costs.
Learn it → Model EvaluationClassical machine learning 6
Precision vs recall — and when do you optimise for each?
Precision = of the items you flagged, how many were right; recall = of the items that should have been flagged, how many you caught. Optimise precision when false positives are costly (spam filter binning real mail); optimise recall when false negatives are costly (missing a disease or fraud).
Learn it → Model EvaluationWhy can accuracy be misleading?
On imbalanced data a model can score high by ignoring the rare class — 99% accuracy predicting "not fraud" on data that is 99% not-fraud is useless. Accuracy hides which errors you make; precision, recall, and a confusion matrix show it.
Learn it → Model EvaluationWhat is regularization? L1 vs L2?
Regularization penalises large weights to curb overfitting. L2 (Ridge) shrinks weights smoothly toward zero; L1 (Lasso) can drive some weights exactly to zero, doing feature selection. L1 gives sparse models; L2 handles correlated features more gracefully.
Learn it → RegressionBagging vs boosting?
Bagging (e.g. random forests) trains many models in parallel on bootstrapped samples and averages them — it mainly reduces variance. Boosting (e.g. gradient boosting, XGBoost) trains models sequentially, each fixing the previous one’s mistakes — it mainly reduces bias but can overfit.
Learn it → Trees & EnsemblesWhat is cross-validation and why use it?
k-fold CV splits the data into k parts, trains on k−1 and validates on the held-out fold, rotating through all k — then averages the scores. It uses all the data for both training and validation and gives a more stable estimate than a single split.
Learn it → Model EvaluationWhat is the curse of dimensionality?
As features grow, data becomes sparse and distances between points become almost equal, so notions like "nearest neighbour" break down and models need exponentially more data. It motivates dimensionality reduction (PCA) and good feature selection.
Learn it → Clustering & PCADeep learning 6
Why do neural nets need non-linear activation functions?
Stacking linear layers is still just one linear function — no matter how deep, it can only draw straight boundaries. A non-linearity (ReLU, etc.) between layers lets the network compose curves and represent arbitrarily complex functions.
Learn it → Neural NetworksExplain backpropagation.
It is the chain rule applied layer by layer. After a forward pass computes the loss, backprop propagates the gradient of the loss backward through each layer, giving how much every weight contributed to the error — which the optimiser then uses to nudge weights downhill.
Learn it → Backprop & TrainingWhat is the vanishing gradient problem?
In deep or recurrent nets, gradients multiplied through many layers can shrink toward zero, so early layers barely learn. Fixes include ReLU activations, residual connections, careful init, batch norm, and gated units (LSTM/GRU) for sequences.
Learn it → Sequence ModelsExplain self-attention.
Each token computes a query, key, and value; it scores its query against every token’s key, softmaxes those scores into weights, and returns the weighted sum of values. This lets every token look at every other token directly — the core of the transformer.
Learn it → TransformersWhat is transfer learning?
Take a model pretrained on a huge dataset and adapt it to your smaller task — freeze or lightly fine-tune its learned features and train a new head. It gets strong results from little data because the low-level features (edges, textures, language patterns) transfer.
Learn it → CNNs & VisionWhat do dropout and batch norm do?
Dropout randomly zeros a fraction of activations during training so the net can’t rely on any one unit — a regulariser that reduces overfitting. Batch norm normalises layer inputs per mini-batch, stabilising and speeding up training.
Learn it → Backprop & TrainingLLMs & generative AI 7
How does an LLM actually generate text?
It predicts the probability of the next token given all previous tokens, samples one, appends it, and repeats. Everything — answering, coding, reasoning — is that one next-token loop over a huge learned distribution.
Learn it → How LLMs WorkWhat causes hallucinations and how do you reduce them?
The model optimises for plausible-sounding text, not truth, so with weak or missing knowledge it confidently fabricates. Reduce it by grounding answers in retrieved sources (RAG), asking for citations, lowering temperature, and adding evals/guardrails — you reduce, not eliminate.
Learn it → RAGRAG vs fine-tuning — when do you use each?
RAG injects fresh or private knowledge at query time by retrieving relevant text into the prompt — best for facts that change or must be cited. Fine-tuning changes the model’s weights — best for teaching a style, format, or skill. Often you prompt first, add RAG for knowledge, and fine-tune last.
Learn it → Fine-tuningWhat is an embedding, and what is a vector database for?
An embedding maps text (or images) to a vector where similar meanings sit close together. A vector database stores millions of these and finds the nearest ones fast with approximate-nearest-neighbour indexes — the retrieval backbone of RAG and semantic search.
Learn it → Vector DatabasesWhat is LoRA / parameter-efficient fine-tuning?
Instead of updating all of a model’s weights, LoRA freezes them and trains small low-rank adapter matrices added alongside — a tiny fraction of the parameters. You get most of the benefit of fine-tuning at a fraction of the compute and storage.
Learn it → Fine-tuningWhat is an AI agent, and what is a "harness"?
An agent is an LLM in a loop that can call tools: the model decides an action, the program runs it, feeds the result back, and repeats until done. The harness is that surrounding program — the tool registry, the loop, history, and the guards that make it reliable.
Learn it → Build an Agent HarnessHow do you evaluate an LLM application?
Manual spot-checking doesn’t scale. Build an eval set of inputs with expected properties, score outputs automatically (exact match, rules, or an LLM-as-judge), and run it like a regression test on every prompt or model change — while watching the judge’s own biases.
Learn it → Evals & GuardrailsML system design 5
How would you build a RAG chatbot over a company’s docs?
Ingest and chunk the docs, embed each chunk into a vector database, and at query time embed the question, retrieve the top-k relevant chunks, put them in the prompt, and have the LLM answer grounded in them — with citations, guardrails, and evals to catch regressions.
Learn it → RAGHow do you deploy a model to production?
Wrap it behind an API (e.g. FastAPI) with validated request/response schemas, containerise it (Docker), and serve it — choosing batch vs real-time by latency needs. Then add monitoring, logging, and versioning so you can roll back.
Learn it → Deploying a ModelWhat is model/data drift and how do you monitor it?
Drift is when live data diverges from training data (data drift) or the input→output relationship changes (concept drift), so accuracy silently decays. Monitor input distributions and, when labels arrive, live metrics — and retrain or alert when they move.
Learn it → MLOps BasicsHow do you scale similarity search to millions of vectors?
Brute-force cosine is O(n) and stops scaling, so use an approximate-nearest-neighbour index (HNSW, IVF) in a vector database — trading a little recall for huge speed, plus metadata filters and sharding.
Learn it → Vector DatabasesHow would you design a recommendation system?
Start with the signal: content-based (item features) for cold start, collaborative filtering (the user–item matrix) once you have interactions, and matrix factorization / embeddings at scale. Serve candidates fast, then rerank, and measure with online metrics, not just offline scores.
Learn it → Recommender SystemsPractical & behavioural 4
How do you approach a brand-new ML problem end to end?
Frame the problem and the metric first, explore and clean the data, build a dumb baseline, then iterate: features, model, evaluation on a held-out set — and only ship if it beats the baseline by enough to matter. Simple and correct beats clever and fragile.
Learn it → First ML ProjectA model works in your notebook but fails in production. How do you debug?
Check for train/serve skew: different preprocessing, a scaler fit on the wrong data, feature order, dtypes, or data drift. Reproduce with the exact production input, compare features at each step, and add logging — it is almost always the data pipeline, not the model.
Learn it → MLOps BasicsHow do you decide whether a problem even needs ML?
If a few clear rules solve it, use rules — they’re cheaper and debuggable. ML earns its complexity only when the pattern is real but too intricate to hand-code, you have representative labelled data, and being occasionally wrong is acceptable.
Learn it → What AI Actually IsHow do you keep up with a field moving this fast?
Depth over hype: master the fundamentals (they change slowly), follow a few high-signal sources, and learn new things by building with them. The "What’s next" page collects free courses, books, and newsletters worth your time.
Want the full picture behind these answers? Work through theroadmap, then build theprojects — nothing proves you can do the job like shipped work.