24 September 2026 · 19 min read
Machine learning interview questions for beginners, with answers
About 30 machine learning questions that come up in junior ML, data science, and ML engineering interviews, each with a short answer and the follow-up an interviewer usually asks next, grouped from data and evaluation through training, metrics, neural networks, and architectures.
A beginner machine learning interview checks whether you can explain the fundamentals in your own words: how data is split and evaluated, why models overfit, how training works, which loss and metric fit a problem, what the building blocks of a neural network do, how common architectures such as CNNs and transformers work, and how you would approach a new problem. The questions below are about 30 common ones from junior ML, data science, and ML engineering interviews, grouped by topic in the order the ideas build on each other. Each one has a short answer, the follow-up an interviewer tends to ask next, and a link to a longer post where one exists.
How to use these questions
Read a question, answer it out loud or in writing before reading the answer, then compare. Interviewers usually care less about the exact wording than about whether you can name the mechanism and then handle the follow-up, so the follow-ups are worth practicing as much as the main questions. If an answer below uses a term you could not define on the spot, that term is the thing to study next.

Data and evaluation
What is the difference between supervised and unsupervised learning?
In supervised learning every training example comes with the correct answer, called a label, and the model learns to predict the label from the input: an email and whether it is spam, a house and its price. In unsupervised learning there are no labels, and the model looks for structure in the inputs themselves, such as groups of similar customers (clustering) or a smaller set of features that keeps most of the information (dimensionality reduction).
Likely follow-up: where does self-supervised learning fit? It creates labels from the data itself, for example hiding the next word of a sentence and training the model to predict it, which is how large language models are pretrained.
Why do you split data into training, validation, and test sets?
The model learns its weights on the training set. The validation set is used to make choices, such as the learning rate, the model size, or when to stop training. The test set is used once at the end to estimate how the final model does on data it has never influenced. If the same data is used to both choose and evaluate, the score comes out higher than what the model will get on new data.
Likely follow-up: why not tune on the test set? Every choice made by looking at test scores leaks a little information about the test set into the model, so after enough tuning the test score stops being an estimate of performance on new data.
What is data leakage?
Data leakage is when information that would not be available at prediction time ends up in training, so the model looks better in evaluation than it will be in use. A common example is normalizing features with the mean and standard deviation of the whole dataset before splitting it, which lets the training set see statistics of the test set. Another is having the same patient or user in both the training and test sets, so the model can recognize the person instead of learning the pattern.
Likely follow-up: how would you catch it? A validation score that looks too good for the problem is the first sign. Then check for features that are computed after the outcome happened, duplicate rows across splits, and preprocessing that was fit on the full dataset.
What is cross-validation, and when would you use it?
In k-fold cross-validation the data is split into k equal parts. The model is trained k times, each time on k minus 1 parts and evaluated on the part that was left out, and the k scores are averaged. It gives a more stable estimate than a single validation split, which matters most when the dataset is small. It costs k training runs, so it is less common for large neural networks.
Likely follow-up: what about time series? Shuffling would let the model train on the future and predict the past, so the folds are split by time instead: train on the earliest data, validate on the period right after it, and move the window forward.
How do you handle an imbalanced dataset?
Start with the metric, because accuracy hides the problem: if 99% of transactions are legitimate, a model that predicts "legitimate" for everything gets 99% accuracy and catches no fraud. Precision, recall, and the precision-recall curve show what is happening to the rare class. Then there are three common fixes: weight the rare class more in the loss (in PyTorch, pos_weight in BCEWithLogitsLoss), resample the training set so the rare class shows up more often, and move the decision threshold away from 0.5.
Likely follow-up: should you resample the test set too? No, resampling is applied to the training set only, so the test set keeps the real class ratio the model will face.
Overfitting and generalization
What are overfitting and underfitting, and how do you spot them?
A model overfits when it learns the training data, including its noise, so well that it does worse on new data. The sign is a training loss that keeps falling while the validation loss stops falling and starts to rise. A model underfits when it is too simple or trained too briefly to capture the pattern at all, and then both the training and validation losses stay high. Overfitting vs underfitting has the three loss-curve shapes and the fixes for each.
Likely follow-up: your model overfits, what do you try first? More data if it is available, then regularization such as weight decay or dropout, a smaller model, or early stopping.
Explain the bias-variance tradeoff.
Bias is error that comes from a model being too simple to fit the pattern, such as a straight line fitted to a curve. Variance is error that comes from a model being so sensitive to its training data that a different sample of data would give a very different model. Making a model more flexible usually lowers bias and raises variance, so the validation error first drops and then climbs as flexibility grows, and the goal is the point in between. More on this in the bias-variance tradeoff.
Likely follow-up: how do you tell which one you have? High training error means high bias. Low training error with much higher validation error means high variance.
What is regularization? What is the difference between L1 and L2?
Regularization is any change to training that discourages the model from fitting noise. L2 regularization adds the sum of squared weights to the loss, which pulls every weight toward zero in proportion to its size, so large weights shrink fast and small weights shrink slowly. L1 adds the sum of absolute weights, which pulls every weight toward zero by the same amount per step regardless of its size, so many weights end up at exactly zero. Regularization explained covers both with code.
Likely follow-up: why does L1 give exact zeros and L2 does not? The L2 pull shrinks as the weight shrinks, so the weight gets closer to zero without reaching it. The L1 pull stays the same size all the way down, so a weight that is not needed gets pushed to zero and stays there.
How does dropout work?
During training, dropout sets each activation in a layer to zero with probability $p$, a new random choice for every batch, and scales the remaining activations by $1/(1-p)$ so their expected sum stays the same. The network cannot rely on any single unit being present, so it spreads what it learns across many units, which reduces overfitting. At evaluation time dropout is turned off and every unit is used.
Likely follow-up: what goes wrong if you forget model.eval() in PyTorch? Dropout stays on during evaluation, so predictions are noisy and the validation score comes out lower than it should.
What is early stopping?
Early stopping tracks the validation loss after each epoch and stops training when it has not improved for a set number of epochs, called the patience. The weights from the epoch with the best validation loss are the ones kept. It stops the model at the point before it starts to overfit, and it saves training time.
Likely follow-up: why keep the best checkpoint instead of the last one? By the time training stops, the model has already trained for several epochs past its best validation loss.
Training
What is a loss function?
A loss function takes the model's predictions and the correct answers and returns one number that says how wrong the predictions are. Training changes the weights to make that number smaller, so the loss defines what "good" means for the model. Mean squared error is common for predicting numbers and cross-entropy for predicting classes. What is a loss function goes through which loss fits which task.
Likely follow-up: why not train directly on accuracy? Accuracy only changes when a prediction flips from wrong to right, so tiny changes to the weights usually leave it the same and it gives no gradient to follow.
What is gradient descent?
Gradient descent is the algorithm that updates the weights to reduce the loss. The gradient of the loss with respect to each weight says how much the loss would change if that weight moved a little, and its sign says which direction increases the loss. Each step moves every weight a small amount in the opposite direction:
$$w \leftarrow w - \eta , \frac{\partial \mathcal{L}}{\partial w}$$
Here $w$ is a weight, $\mathcal{L}$ is the loss, and $\eta$ is the learning rate, the size of the step. What is gradient descent builds this from a one-weight example.
Likely follow-up: does it find the global minimum? For a convex loss such as linear regression with MSE, yes. For neural networks the loss is not convex, and gradient descent finds a low point that is usually good enough in practice.
What does the learning rate do, and how do you pick it?
The learning rate sets how far each gradient descent step moves the weights. Too small and the loss falls very slowly. Too large and the loss jumps around or grows until it becomes NaN. A common way to pick it is to try values a factor of 10 apart, such as 1e-4, 1e-3, and 1e-2, and keep the one whose validation loss falls fastest without becoming unstable. More in what is a learning rate.
Likely follow-up: what is a learning rate schedule? A rule for changing the learning rate during training, such as a short warmup from a small value, then a slow decrease (cosine or step decay) so the last steps are small and precise.
What is the difference between batch, stochastic, and mini-batch gradient descent?
They differ in how many examples are used to compute each gradient. Batch gradient descent uses the whole training set for every step, which gives an exact gradient but is slow and needs the whole dataset in memory. Stochastic gradient descent uses one example per step, which is fast but very noisy. Mini-batch gradient descent uses a small group, often 32 to 512 examples, which balances the two and runs well on GPUs, and it is what most people mean by "SGD" in deep learning code.
Likely follow-up: what changes when you increase the batch size? Each gradient is less noisy and each epoch takes fewer steps, it uses more memory, and the learning rate often has to be raised to match.
How is Adam different from SGD?
SGD moves every weight by the same learning rate times its gradient. Adam keeps two running averages for each weight, one of its recent gradients and one of its recent squared gradients, and uses them to give each weight its own step size: weights with consistently large gradients take smaller steps, and weights with small or rare gradients take relatively larger ones. It usually needs less tuning to get a model training, and lr=1e-3 is a common default. The Adam optimizer explained has the full update rule.
Likely follow-up: what is AdamW? Adam with weight decay applied directly to the weights instead of added to the gradient. In plain Adam the per-weight scaling also rescales the decay, which weakens it for exactly the weights with large gradients, and AdamW avoids that.
What is backpropagation?
Backpropagation is the method for computing the gradient of the loss with respect to every weight in a network. It applies the chain rule starting at the loss and working backward through the layers, reusing each layer's result for the layer before it, so the gradients for all the weights cost about as much as one or two extra forward passes. Gradient descent then uses those gradients to update the weights. What is backpropagation works through a full example by hand.
Likely follow-up: why do you call optimizer.zero_grad() in PyTorch? PyTorch adds new gradients to the ones already stored, so without clearing them each step would use the sum of every gradient computed so far.
What are an epoch, a batch, and an iteration?
A batch is the group of examples used for one gradient step. An iteration is one such step. An epoch is one full pass over the training set, so with 10,000 examples and a batch size of 100, one epoch is 100 iterations.
Likely follow-up: how many epochs should you train for? There is no fixed number, which is why early stopping on the validation loss is common.
Your training loss is not going down. What do you check?
Check the training loop before the model: that zero_grad(), backward(), and step() are all called, that the labels line up with the inputs, and that the loss function gets the kind of output it expects (raw scores for CrossEntropyLoss, not probabilities). Then try the learning rate a factor of 10 up and down. A fast test of the whole pipeline is to train on one small batch: a working model and loop should drive the loss on that batch close to zero.
1import torch
2from torch import nn
3
4torch.manual_seed(0)
5x = torch.randn(16, 10) # one small batch: 16 examples, 10 features
6y = torch.randint(0, 3, (16,)) # labels for 3 classes
7
8model = nn.Sequential(nn.Linear(10, 64), nn.ReLU(), nn.Linear(64, 3))
9loss_fn = nn.CrossEntropyLoss()
10optimizer = torch.optim.Adam(model.parameters(), lr=1e-2)
11
12for step in range(300):
13 optimizer.zero_grad()
14 loss = loss_fn(model(x), y)
15 loss.backward()
16 optimizer.step()
17
18print(f"loss after 300 steps: {loss.item():.4f}")If the loss on this one batch stays high, the bug is in the loop, the labels, or the loss, not in the amount of data. The loss-not-decreasing checklist has the rest.
Likely follow-up: what if the loss becomes NaN? Common causes are a learning rate that is too high, a log of zero or division by zero in a custom loss, and bad values in the input data.
Losses and metrics
When do you use mean squared error, and when cross-entropy?
Mean squared error (MSE) is the usual choice when the model predicts a number, such as a price. Cross-entropy is the usual choice when the model predicts a class: it is the negative log of the probability the model gave to the correct class, so a confident wrong answer gets a very large loss and a large gradient. MSE on class probabilities gives small gradients exactly when the model is confidently wrong, so it learns slowly there.
| Task | Model output | PyTorch loss |
|---|---|---|
| Predict a number | one raw value | nn.MSELoss |
| Yes or no | one raw score | nn.BCEWithLogitsLoss |
| One of several classes | one raw score per class | nn.CrossEntropyLoss |
| Several labels at once | one raw score per label | nn.BCEWithLogitsLoss |
Likely follow-up: why do the PyTorch classification losses take raw scores instead of probabilities? They apply the sigmoid or softmax inside, in a form that stays numerically stable when the scores are very large or very small.
What are precision, recall, and F1?
Say a spam filter looks at 100 emails, 12 of which are spam. It flags 10: 8 of them really are spam and 2 are not, and it misses the other 4 spam emails. Precision is the share of flagged emails that were spam, 8 out of 10 or 0.80. Recall is the share of spam emails that got flagged, 8 out of 12 or about 0.67. F1 is the harmonic mean of the two, about 0.73, which stays low if either one is low.

Likely follow-up: when would you care more about recall? When a missed case costs more than a false alarm, such as screening for a disease, where a false alarm leads to a second test but a miss goes untreated. Precision matters more when false alarms are expensive, such as blocking a customer's card.
What does ROC AUC measure?
The ROC curve plots the true positive rate against the false positive rate as the decision threshold moves from 1 down to 0. The area under it (AUC) is the probability that the model gives a randomly chosen positive example a higher score than a randomly chosen negative one, so 0.5 is random guessing and 1.0 is a perfect ranking. It measures how well the model ranks examples, independent of any single threshold.
Likely follow-up: when is it misleading? With a very rare positive class, a model can have a high ROC AUC and still flag many false positives for every real one, and the precision-recall curve shows that more clearly.
Neural networks
Why do neural networks need activation functions?
Without them, every layer is a matrix multiplication plus a bias, and any number of those stacked together collapses into one linear function, so a deep network could only draw straight decision boundaries. An activation function such as ReLU, which outputs $\max(0, x)$, is applied after each layer and makes the network nonlinear, which lets it fit curved patterns. Activation functions goes from step and sigmoid to GELU.
Likely follow-up: why ReLU instead of sigmoid in hidden layers? The sigmoid's gradient is at most 0.25 and close to zero for large inputs, which slows learning in deep networks. ReLU's gradient is 1 for every positive input, and it is cheap to compute.
What is the vanishing gradient problem?
In backpropagation the gradient for an early layer is a product of one factor per layer after it. If those factors are mostly below 1, as with sigmoid activations, the product shrinks toward zero as the network gets deeper, and the early layers barely learn. Common fixes are ReLU-family activations, careful weight initialization, normalization layers, and residual connections, which add a layer's input straight to its output so the gradient has a path that skips the layer.
Likely follow-up: what is the opposite problem? Exploding gradients, where the factors are mostly above 1 and the gradient grows until training diverges. Gradient clipping, which caps the size of the gradient, is a common fix.
Why does weight initialization matter?
If every weight in a layer starts at the same value, every unit in that layer computes the same output and gets the same gradient, so they stay identical and the layer behaves like one unit. Random initialization breaks that symmetry. The scale matters too: weights that are too large make activations and gradients grow layer by layer, and weights that are too small make them shrink. Xavier and He initialization set the random scale from the number of inputs to each layer to keep activations at a similar size through the network.
Likely follow-up: which one goes with ReLU? He initialization, because ReLU zeroes about half its inputs and He scales the weights up to make up for it.
What does batch normalization do?
Batch normalization takes each feature in a layer's output and normalizes it across the current batch to mean 0 and standard deviation 1, then multiplies by a learned scale and adds a learned shift. Keeping the activations in a steady range usually lets a network train faster and with higher learning rates. During training it uses the statistics of the current batch, and at evaluation it uses running averages collected during training.
Likely follow-up: how is layer normalization different? It normalizes across the features of one example instead of across the batch, so it does not depend on the batch size and behaves the same in training and evaluation, which is why most transformers use it.
How is logistic regression related to a neural network?
Logistic regression is a single linear layer followed by a sigmoid, trained with binary cross-entropy, which is a neural network with no hidden layers. It can only separate classes with a straight line (or a flat plane in more dimensions). Adding hidden layers with nonlinear activations is what lets a network learn curved boundaries.
Likely follow-up: when would you use logistic regression instead? As a first baseline for classification, and as the final model on small tabular datasets where it is often competitive, easy to explain, and fast to train.
Architectures
What does a convolutional layer do, and why is it used for images?
A convolutional layer slides a small grid of weights, called a kernel or filter, across the image and computes a weighted sum at every position, producing a map of where a pattern such as an edge appears. The same kernel weights are used at every position, so the layer needs far fewer parameters than a fully connected layer on the same image, and a pattern learned in one corner can be detected anywhere. Stacking layers lets later layers combine edges into textures, parts, and objects.
Likely follow-up: what does pooling do? It shrinks each feature map, for example keeping the largest value in every 2 by 2 block, which reduces computation and makes the output less sensitive to small shifts in position.
What is attention?
Attention lets each position in a sequence build its output from all the other positions, weighted by how relevant each one is. Every token is turned into a query, a key, and a value vector. The weights come from comparing one token's query with every token's key, and the output is the weighted sum of the values:
$$\text{Attention}(Q, K, V) = \text{softmax}!\left(\frac{QK^\top}{\sqrt{d_k}}\right) V$$
$Q$, $K$ and $V$ hold the query, key, and value vectors of all the tokens as rows, and $d_k$ is the length of each key vector. The softmax turns each row of scores into weights that add up to 1.
Likely follow-up: why divide by $\sqrt{d_k}$? Dot products of longer vectors tend to be larger, and large scores push the softmax toward putting almost all the weight on one token, where its gradients are close to zero. Dividing keeps the scores in a range where the softmax still learns.
What is transfer learning, and what is fine-tuning?
Transfer learning starts from a model that was already trained on a large dataset and reuses what it learned for a new task, instead of training from random weights. Fine-tuning is a common way to do it: replace the output layer to fit the new task and continue training on the new data, usually with a small learning rate so the pretrained weights change only a little. With very little data, a common option is to freeze the pretrained layers and train only the new output layer.
Likely follow-up: why does it work? The early layers of a model trained on a large dataset learn general features, such as edges in images or word meanings in text, that are useful for many tasks, so the new task needs less data to learn on top of them.
Practical questions
How would you approach a new machine learning problem?
Start from the goal and the metric: what decision the model supports and how success will be measured. Look at the data before modeling: how much there is, how the labels were made, whether the classes are balanced, and what could leak. Build a simple baseline first, such as predicting the most common class or a logistic regression, so every later model has a number to beat. Then try a stronger model, compare on the validation set, and look at the examples it gets wrong.
Likely follow-up: why start with a baseline? Without one, there is no way to tell whether a 90% accuracy is good, and on imbalanced data predicting the majority class alone can already reach it.
Tell me about a project you built.
This question is really a set of smaller ones: what problem you picked and why, what data you used, what baseline you compared against, which models you tried, how you evaluated them, and what you would do differently. A good answer gives numbers for each model against the baseline and names one thing that did not work. ML projects that get you hired has project ideas built to hold up to these questions.
Likely follow-up: why didn't you try X? A good answer names a reason (not enough data, the baseline was already close, the time went to evaluation) or says what you expect X would change.
How to practice them
Reading the answers is the easy part, and answering the same question from memory a week later is closer to what an interview asks for. Practice each question until you can explain it without notes, come back to the ones you missed a few days later, and practice the follow-ups as well. In QuiddityML, every unit ends with interview questions on that unit's material: you write your answer first, then reveal a model answer with a note on what the interviewer is checking for, and the concepts you get wrong in the exercises come back sooner in your reviews.