All jobs / Data science / ML / AI
ML Algorithms interview questions
ML Algorithms questions a Data science / ML / AI can be asked, from first job to senior. Open one to see the strongest answer and why it works.
You need to predict whether a customer will churn. Why not fit a linear regression to a 0/1 target?
The strongest answer: Linear regression outputs unbounded values, so you get probabilities below 0 or above 1 and the wrong error assumptions; logistic regression passes the linear score through a sigmoid to give a calibrated probability
Why it works: Right — same linear score underneath, but the sigmoid link and the log-loss make the output a probability you can threshold and trust.
- Yes/no target: logistic, not linear.
- Sigmoid bounds the output to 0–1.
- Log-loss fits probabilities.
- Same linear score underneath.
How does a decision tree decide where to split, and why does a tree with unlimited depth usually disappoint?
The strongest answer: At each node it picks the feature and threshold that best reduce impurity (Gini or entropy for classes, variance for regression); grown without limits it keeps splitting until leaves memorise single rows
Why it works: Exactly — greedy impurity reduction per node, and depth or minimum-leaf size is what stops it memorising noise.
- Greedy split: best impurity reduction.
- Gini or entropy; variance for regression.
- Unlimited depth memorises rows.
- Limit depth or leaf size.
They ask what you try before a neural net on tabular churn. Strongest answer?
The strongest answer: A logistic or tree baseline I can explain, on a leak-safe split, with a metric that matches the outreach decision
Why it works: Exactly. Explainable floor first. GPUs are not a substitute for a question.
- Start with an explainable baseline.
- Leak-safe split + matching metric.
- Do not lead with depth.
- Do not quote a blog as your result.
When would you reach for k-nearest neighbours, and what bites people who use it carelessly?
The strongest answer: Small, low-dimensional data where local similarity is meaningful; it has no training cost but every prediction scans the data, it needs scaled features because distance is the model, and a small k is noisy
Why it works: Right — k-NN is a distance argument; scale, dimensionality and k are the whole story, and prediction cost grows with the data.
- k-NN: distance is the model.
- Scale the features.
- Pick k on validation.
- Prediction cost grows with data.
You run K-means on customer data and the segments look odd. What does K-means assume, and what do you check?
The strongest answer: Roughly spherical, similar-sized clusters in scaled space, with k chosen by you — check feature scaling, run several initialisations, look at the elbow or silhouette, and read the clusters before naming them
Why it works: Exactly — K-means is distance to a centroid, so scale, shape and initialisation drive it; k is a judgement call you validate.
- Centroid distance, spherical clusters.
- Scale first; several inits.
- Choose k with elbow or silhouette.
- Read the clusters before naming them.
Random forest and gradient boosting are both tree ensembles. How do they build their trees differently, and when do you choose each?
The strongest answer: Forest: independent deep trees on bootstrap samples and feature subsets, averaged — robust with little tuning. Boosting: shallow trees added sequentially to fit residuals — often stronger on tabular data, but needs a learning rate and early stopping
Why it works: Right — bagging reduces variance by averaging; boosting reduces bias by correcting mistakes, and pays for it in tuning sensitivity.
- Bagging averages; boosting corrects.
- Forest: robust, low tuning.
- Boosting: stronger, sensitive to tuning.
- Early-stop boosting on validation.
What is a support vector machine actually optimising, and what does the kernel trick buy you?
The strongest answer: The widest margin between classes, fixed by the boundary points (the support vectors), with C trading margin against errors; a kernel scores similarity as if in a higher-dimensional space without building it, so a straight boundary there is curved here
Why it works: Exactly — margin plus support vectors plus kernel similarity. Scale the features and tune C and gamma; SVMs are slow on very large data.
- Maximise the margin.
- Support vectors define the boundary.
- Kernel: similarity in a higher space.
- Scale inputs; tune C and gamma.