Machine Learning Interview Questions for 2 Years Experience
40 questions with answers for candidates with 2 years of experience — 7 easy, 30 medium, 3 hard.
What interviewers expect: 2 years experience
At two years, expect deeper questions on gradient boosting, hyperparameter tuning with Optuna, SHAP explanations and calibration. Interviewers check whether you can own a model from problem framing to handover, including evaluation design and stakeholder communication. Basic deployment knowledge such as saving pipelines, FastAPI and Docker is often expected. Expect a take-home task.
This set is weighted towards ML Fundamentals (8), MLOps and Deployment (7), Clustering and Dimensionality Reduction (6), Data Preprocessing and Feature Engineering (5).
XGBoost and LightGBM tuning Model explainability Evaluation design Basic model serving
Solved at this levelStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
✓ 3 questions free • Unlock the rest in seconds
01
Validation AUC is 0.99 on a loan default model. What do you suspect?
Such a high score on a hard problem usually signals leakage. I would check feature importances for a suspiciously dominant feature, look for fields recorded after the loan outcome such as collection status, verify preprocessing was fit only on training data, and check for duplicate customers across train and test. Then re-run with a time-based split to confirm a realistic score.
Softmax turns a vector of raw scores into probabilities that sum to one: p_i = exp(z_i) / sum of exp(z_j). It is used in multinomial logistic regression and the output layer of neural networks for multiclass problems. Larger scores get exponentially larger shares. In practice the maximum score is subtracted before exponentiation to avoid numerical overflow.
Bagging trains many models on bootstrap samples, random samples with replacement, and averages their predictions to reduce variance. A random forest adds feature randomness: each split considers only a random subset of features, controlled by max_features. This de-correlates the trees, so averaging helps more. Out-of-bag samples, about 37 percent left out per tree, give a free validation estimate.
04
Write a unit test for a model prediction function.
Possible causes: leakage inside CV, such as preprocessing or feature selection fit outside folds; repeated tuning that overfit the CV folds; a test set from a different time period or population; or duplicate entities across folds but not test. I would check pipeline structure, switch to time-based or group splits that match how test data differs, and compare feature distributions between the two sets.
06
40 percent of values in an important income column are missing. What do you do?
I would study the missingness pattern first, for example whether self-employed applicants skip it. I would add a binary was_missing feature, impute with the median within relevant groups or use IterativeImputer, and compare against models that handle missing values natively, like HistGradientBoosting or XGBoost. I would also raise the issue with the data owner so collection can improve.
Docker packages the model, code, Python version and exact library versions into one image that runs the same on a laptop, a test server or Kubernetes. This removes 'works on my machine' problems, especially with scikit-learn version mismatches. Images can be scanned, versioned and deployed through CI/CD, and scaled horizontally behind a load balancer on platforms like Kubernetes, ECS or Cloud Run.
08
Run stratified 5-fold cross-validation with multiple metrics.
from sklearn.model_selection import StratifiedKFold, cross_validate
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
res = cross_validate(pipe, X, y, cv=cv,
scoring=['roc_auc', 'average_precision', 'f1'], n_jobs=-1)
for k in ['test_roc_auc', 'test_average_precision', 'test_f1']:
print(k, res[k].mean().round(3), res[k].std().round(3))
Isolation Forest builds random trees that split on random features and random thresholds. Anomalies are few and different, so they get isolated in fewer splits, giving shorter average path lengths. The anomaly score comes from that path length. It is fast, works without labels and scales well. The contamination parameter sets the expected share of anomalies and determines the threshold.
10
The fraud team can only review 500 alerts a day. How do you set the threshold?
Instead of 0.5, rank transactions by predicted probability and pick the threshold that yields about 500 alerts per day on recent data. Then report precision and recall at that cut-off, or precision at k. I would monitor daily alert volume because drift can change it, and recompute the threshold periodically. If cost data exists, I would choose the threshold that maximises expected savings.
Bias is error from overly simple assumptions, which causes underfitting. Variance is error from sensitivity to the particular training sample, which causes overfitting. Increasing model complexity usually lowers bias but raises variance. The goal is the complexity that minimises total test error. For example, a linear model on curved data has high bias, while a very deep unpruned tree has high variance.
12
Explain gradient descent and the role of the learning rate.
Gradient descent minimises a loss by repeatedly moving parameters in the direction of the negative gradient: w = w - learning_rate * gradient. The learning rate controls step size. Too high and the loss oscillates or diverges; too low and training is very slow or gets stuck. Variants include batch, stochastic and mini-batch gradient descent, plus adaptive optimisers like Adam.
13
Describe a time you found a serious data quality issue late in a project.
Situation: two days before a demo, I noticed sales for one region were doubled. Task: fix it without missing the deadline. Action: I traced it to a join that duplicated rows on a non-unique key, fixed the join, added row-count assertions to the pipeline and retrained. I informed my lead immediately with the impact. Result: the demo went ahead with correct numbers, and the assertions caught a similar issue later.
14
Your manager asks for a single number showing the model's business value. What do you give?
I would convert model outcomes into money or time using a cost matrix agreed with the business, for example savings from caught fraud minus the cost of reviewing false alerts. I would compare this against the current process or a rule-based baseline on holdout data and show a range rather than one point. A short note on assumptions keeps the number honest.
15
Why do you want to work as a machine learning engineer?
I enjoy turning data into decisions that people actually use. During my projects I liked the full cycle: framing the problem, cleaning messy data, comparing models and explaining results. ML engineering lets me combine coding with statistics and see measurable business impact, such as reducing manual review time. I also want to keep growing into deployment and monitoring, which I am already practising with FastAPI and Docker.
16
XGBoost validation loss starts rising after 300 rounds while training loss keeps falling. What do you do?
That is overfitting beyond about 300 rounds. I would use early stopping with a patience such as 50 rounds on a validation set so training stops at the best iteration, then lower the learning rate, reduce max_depth, add subsample and colsample_bytree below 1, and increase min_child_weight or lambda. The final model is refit using the best iteration count found.
17
How do you create lag and rolling features for a sales forecasting model in pandas?
Sort by item and date, then shift so features use only past values.
df = df.sort_values(['item', 'date'])
g = df.groupby('item')['sales']
df['lag_7'] = g.shift(7)
df['roll_mean_28'] = g.transform(lambda s: s.shift(1).rolling(28).mean())
The shift before rolling prevents the current day's sales from leaking into its own feature.
18
Your real-time model API takes 400 ms but the requirement is under 50 ms. What do you do?
Profile first to see whether time goes to feature lookup, preprocessing or the model. Then cache or precompute features, load the model once at startup, reduce trees or features, use a faster library like LightGBM or ONNX Runtime, and batch requests if possible. Run several workers and keep the service close to its data store. Re-measure p95 and p99 latency, not just the average.
19
What should you monitor for a model in production?
Monitor service health such as latency, error rate and throughput; input data quality such as missing values, schema changes and out-of-range values; feature and prediction distribution drift; and real performance once labels arrive. Also track business KPIs the model influences. Set alerts with thresholds and owners, and keep a dashboard so issues are found before users report them.
An SVM finds the hyperplane that separates classes with the maximum margin, and the points on the margin are the support vectors. The soft-margin version uses C to trade off margin width against misclassification. Kernels like RBF or polynomial let SVMs learn non-linear boundaries by implicitly mapping data to higher dimensions. SVMs need scaled features and become slow beyond roughly a hundred thousand rows.
21
What is the difference between batch, stochastic and mini-batch gradient descent?
Batch gradient descent uses the full dataset for each update, giving stable but slow and memory-heavy steps. Stochastic gradient descent updates after every single example, which is fast and noisy and can escape shallow minima. Mini-batch uses small groups such as 32 to 512 rows, balancing stability with speed and allowing vectorised computation. Mini-batch is the default in practice.
22
What is association rule mining? Explain support, confidence and lift.
Association rule mining finds items that occur together, such as in market basket analysis. Support is how often an itemset appears in all transactions. Confidence of A to B is the share of transactions with A that also contain B. Lift is confidence divided by B's support; lift above 1 means A and B occur together more than by chance. Apriori and FP-Growth are common algorithms.
23
How do you build a scikit-learn pipeline for mixed numeric and categorical data?
Use ColumnTransformer inside a Pipeline so preprocessing is fit only on training folds.
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
num = Pipeline([('imp', SimpleImputer(strategy='median')), ('sc', StandardScaler())])
pre = ColumnTransformer([
('num', num, num_cols),
('cat', OneHotEncoder(handle_unknown='ignore'), cat_cols)
])
model = Pipeline([('pre', pre), ('clf', LogisticRegression(max_iter=1000))])
24
Find the most similar items using cosine similarity.
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.neighbors import NearestNeighbors
X = TfidfVectorizer(min_df=2).fit_transform(df['title'])
nn = NearestNeighbors(n_neighbors=6, metric='cosine').fit(X)
dist, idx = nn.kneighbors(X[0])
print(df['title'].iloc[idx[0][1:]].tolist())
The first neighbour is the item itself, so skip it.
25
Compute permutation importance on validation data.
from sklearn.inspection import permutation_importance
import pandas as pd
r = permutation_importance(model, X_val, y_val, n_repeats=10,
scoring='roc_auc', random_state=42, n_jobs=-1)
imp = pd.Series(r.importances_mean, index=X_val.columns)
print(imp.sort_values(ascending=False))
Near-zero or negative values mean the feature adds little on unseen data.
Data drift, or covariate shift, means the distribution of input features changes, such as average order value rising after a pricing change. Concept drift means the relationship between features and target changes, such as fraud patterns evolving. Data drift can be detected without labels using PSI or KS tests; concept drift usually needs labels and shows up as falling performance. Both trigger investigation and retraining.
27
How do you implement simple gradient descent for linear regression in NumPy?
Compute predictions, the gradient of MSE, and update weights in a loop.
import numpy as np
w = np.zeros(X.shape[1]); b = 0.0; lr = 0.01
for _ in range(1000):
err = X @ w + b - y
w -= lr * (2 / len(y)) * (X.T @ err)
b -= lr * (2 / len(y)) * err.sum()
Scale features first or the loop converges slowly.
28
What is heteroscedasticity and why does it matter?
Heteroscedasticity means the variance of residuals changes with the level of the prediction, such as errors growing for expensive houses. Predictions remain unbiased, but standard errors and p-values become unreliable. Detect it with a residuals versus fitted plot or the Breusch-Pagan test. Fixes include log-transforming the target, weighted least squares, or robust standard errors.
29
You are asked to predict customer churn. How would you frame the ML problem from scratch?
First define churn precisely, for example no purchase in 60 days, and the prediction window. It becomes binary classification. Build features from data available before the cut-off date only, choose a time-based split, and pick metrics like recall at a fixed precision or lift in the top decile. Start with logistic regression as a baseline, then try boosting, and agree on how retention teams will use the scores.
30
Random forest and LightGBM give the same AUC. Which would you deploy?
I would compare beyond AUC: model size, inference latency, training time, calibration and stability across time periods. LightGBM is usually smaller and faster to score, while random forest needs less tuning and is less prone to overfitting. If both are equal, I would choose the one that is cheaper to run and easier for the team to maintain and retrain.
31
How do you select the top k features using mutual information in scikit-learn?
SelectKBest with mutual_info_classif captures non-linear relationships, unlike plain correlation.
from sklearn.feature_selection import SelectKBest, mutual_info_classif
sel = SelectKBest(score_func=mutual_info_classif, k=20)
X_new = sel.fit_transform(X_train, y_train)
print(X_train.columns[sel.get_support()])
Put the selector inside a pipeline so selection is redone in each CV fold.
32
Your team retrains models manually in notebooks every month. How would you improve it?
I would convert the notebook into a versioned training pipeline with separate steps for data extraction, validation, feature building, training and evaluation, scheduled with Airflow or a cloud pipeline. Each run would log to MLflow, compare against the production model on a fixed holdout, and register the new model only if it passes thresholds. Promotion would stay a reviewed step, at least initially.
33
Tell me about a time your model did not work as expected. What did you do?
Situation: my first churn model scored 0.95 AUC in validation but failed in a pilot. Task: find out why. Action: I traced features and found one field updated after customers left, which leaked the label. I removed it, rebuilt features with a strict cut-off date and moved to a time-based split. Result: AUC dropped to 0.78 but held steady in production, and I added a leakage checklist to my workflow.
34
A product team wants 'similar products' recommendations with no purchase labels. How would you start?
I would build product embeddings from content: TF-IDF or sentence embeddings of titles and descriptions, plus category and price features. Then use cosine similarity with nearest-neighbour search, such as scikit-learn NearestNeighbors or an approximate index like FAISS for large catalogues. I would review samples with the product team and later add co-view or co-purchase signals once collected.
35
Check calibration with a reliability curve and Brier score.
from sklearn.calibration import CalibrationDisplay
from sklearn.metrics import brier_score_loss
proba = clf.predict_proba(X_test)[:, 1]
print('Brier', brier_score_loss(y_test, proba))
CalibrationDisplay.from_predictions(y_test, proba, n_bins=10)
plt.show()
Points on the diagonal mean predicted probabilities match observed frequencies.
from sklearn.ensemble import IsolationForest
iso = IsolationForest(n_estimators=300, contamination=0.01, random_state=42)
iso.fit(X_train)
scores = -iso.score_samples(X_new)
flags = iso.predict(X_new) == -1
Higher scores mean more anomalous. Tune contamination to match how many alerts reviewers can handle.
37
k-means gives one huge cluster and several tiny ones. What could be wrong?
Likely causes are unscaled features, where one large-range feature dominates distance; heavy skew or outliers pulling centroids; or data that is not naturally spherical. I would log-transform and scale features, remove or cap extreme outliers, and try different k values. If shapes are irregular, DBSCAN, HDBSCAN or a Gaussian Mixture Model may fit better.
38
How do you work with data engineers and software engineers on an ML project?
I agree early on interfaces: which tables or APIs provide features, the input and output schema, latency targets and who owns monitoring. I share a short design document and keep my code in the same repository standards as theirs, with tests and reviews. In my last project weekly syncs with data engineering helped us fix a late-arriving data issue before launch rather than after.
39
How would you build a quick baseline before trying complex models?
Use a DummyClassifier or DummyRegressor to see the score of a trivial guess, then a simple model.
from sklearn.dummy import DummyClassifier
base = DummyClassifier(strategy='most_frequent')
base.fit(X_train, y_train)
print(base.score(X_test, y_test))
Any real model must clearly beat this number; otherwise the features carry little signal.
Linear regression assumes a linear relationship between features and target, independent errors, constant error variance (homoscedasticity), normally distributed errors for valid inference, and little multicollinearity among features. Violations mainly hurt confidence intervals and coefficient interpretation more than raw predictions. Check them with residual plots, Q-Q plots, the Durbin-Watson test and VIF.
Frequently asked questions
What is asked in Machine Learning interviews for 2 years of experience?
At two years, expect deeper questions on gradient boosting, hyperparameter tuning with Optuna, SHAP explanations and calibration. Interviewers check whether you can own a model from problem framing to handover, including evaluation design and stakeholder communication. Basic deployment knowledge such as saving pipelines, FastAPI and Docker is often expected. Expect a take-home task.
How many questions should I practise before a Machine Learning interview?
Work through all 40 questions here, then the company-wise sets for the employers you are targeting. Quality matters more than count: be able to explain why each answer is right.
Which topics matter most for 2 years of experience?
Focus first on XGBoost and LightGBM tuning, Model explainability, Evaluation design, Basic model serving.