Machine Learning Interview Questions: Concepts and Answers
Machine learning concept questions are easy to answer with definitions and hard to answer well. Seven core concepts are shown here in numbers from 30,000 real credit card clients: the accuracy trap, overfitting by tree depth, L1 regularisation, thresholds, calibration, cross-validation spread and learning curves.
GloryTecks Team
Training & Placement Faculty
Last updated: 8 October 2026
Machine learning interview questions about concepts, such as overfitting, regularisation and thresholds, are easy to answer with a definition and hard to answer well. A strong answer shows you have watched the concept happen: how much the test score dropped, what the threshold changed, how far the folds disagreed. Each concept below is shown in numbers from one real dataset.
The data is the UCI Default of Credit Card Clients set: 30,000 credit card holders in Taiwan, with their credit limit, six months of payment status, bills and payments, and whether they defaulted the next month (UCI: credit card default). Sex, marital status and age are left out of the features: they are protected attributes in credit decisions in many countries, and an interviewer may ask why you would remove them, and why removing them is not enough on its own, since other features can act as proxies.
import numpy as np
import pandas as pd
from sklearn.calibration import calibration_curve
from sklearn.dummy import DummyClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, brier_score_loss, precision_score, recall_score, roc_auc_score
from sklearn.model_selection import StratifiedKFold, cross_val_score, train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
credit = pd.read_excel("credit.xls", header=1) # UCI Default of Credit Card Clients (Taiwan, 2005)
y = credit.pop("default payment next month")
X = credit.drop(columns=["ID", "SEX", "MARRIAGE", "AGE"]) # leave out protected attributes
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)
print(f"M1 {len(X):,} clients, {y.mean():.1%} defaulted")
dummy = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
print(f" always predict 'no default': accuracy {accuracy_score(y_test, dummy.predict(X_test)):.3f}, "
f"recall {recall_score(y_test, dummy.predict(X_test)):.3f}")
print("\nM2 tree depth: training vs test AUC")
for depth in (2, 5, 10, 20, None):
tree = DecisionTreeClassifier(max_depth=depth, random_state=0).fit(X_train, y_train)
auc = [roc_auc_score(t, tree.predict_proba(x)[:, 1]) for x, t in ((X_train, y_train), (X_test, y_test))]
print(f" max_depth={str(depth):<5} train {auc[0]:.3f} | test {auc[1]:.3f}")
print("\nM3 L1 regularisation: smaller C, fewer features")
for C in (1.0, 0.01, 0.001):
lasso = make_pipeline(StandardScaler(), LogisticRegression(C=C, l1_ratio=1.0, solver="liblinear")).fit(X_train, y_train)
kept = int(np.sum(lasso[-1].coef_ != 0))
print(f" C={C:<6} features kept {kept:>2} of {X.shape[1]} | test AUC {roc_auc_score(y_test, lasso.predict_proba(X_test)[:, 1]):.3f}")
forest = RandomForestClassifier(300, min_samples_leaf=20, random_state=0, n_jobs=-1).fit(X_train, y_train)
p = forest.predict_proba(X_test)[:, 1]
print(f"\nM4 random forest test AUC {roc_auc_score(y_test, p):.3f}; precision and recall depend on the threshold")
for t in (0.5, 0.3, 0.2):
pred = (p >= t).astype(int)
print(f" threshold {t}: precision {precision_score(y_test, pred):.3f} | recall {recall_score(y_test, pred):.3f} | flagged {pred.mean():.1%}")
print("\nM5 are the probabilities calibrated? (mean predicted vs observed default rate, by bin)")
logit = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)).fit(X_train, y_train)
for name, prob in (("random forest", p), ("logistic", logit.predict_proba(X_test)[:, 1])):
observed, predicted = calibration_curve(y_test, prob, n_bins=5, strategy="quantile")
print(f" {name:<13} Brier {brier_score_loss(y_test, prob):.4f} | top bin predicted {predicted[-1]:.2f} vs observed {observed[-1]:.2f}")
scores = cross_val_score(RandomForestClassifier(100, min_samples_leaf=20, random_state=0, n_jobs=-1), X, y,
cv=StratifiedKFold(5, shuffle=True, random_state=0), scoring="roc_auc")
print(f"\nM6 5-fold AUC {scores.mean():.3f} +/- {scores.std():.3f}; folds range {scores.min():.3f} to {scores.max():.3f}")
print("\nM7 learning curve: more training data")
for n in (500, 2000, 8000, len(X_train)):
small = RandomForestClassifier(300, min_samples_leaf=20, random_state=0, n_jobs=-1).fit(X_train[:n], y_train[:n])
print(f" {n:>6,} rows -> test AUC {roc_auc_score(y_test, small.predict_proba(X_test)[:, 1]):.3f}")M1 30,000 clients, 22.1% defaulted
always predict 'no default': accuracy 0.779, recall 0.000
M2 tree depth: training vs test AUC
max_depth=2 train 0.695 | test 0.690
max_depth=5 train 0.770 | test 0.747
max_depth=10 train 0.833 | test 0.714
max_depth=20 train 0.974 | test 0.599
max_depth=None train 1.000 | test 0.615
M3 L1 regularisation: smaller C, fewer features
C=1.0 features kept 19 of 20 | test AUC 0.711
C=0.01 features kept 14 of 20 | test AUC 0.711
C=0.001 features kept 2 of 20 | test AUC 0.692
M4 random forest test AUC 0.778; precision and recall depend on the threshold
threshold 0.5: precision 0.675 | recall 0.346 | flagged 11.3%
threshold 0.3: precision 0.528 | recall 0.549 | flagged 23.0%
threshold 0.2: precision 0.415 | recall 0.679 | flagged 36.2%
M5 are the probabilities calibrated? (mean predicted vs observed default rate, by bin)
random forest Brier 0.1353 | top bin predicted 0.55 vs observed 0.56
logistic Brier 0.1465 | top bin predicted 0.46 vs observed 0.54
M6 5-fold AUC 0.781 +/- 0.010; folds range 0.765 to 0.793
M7 learning curve: more training data
500 rows -> test AUC 0.753
2,000 rows -> test AUC 0.766
8,000 rows -> test AUC 0.771
21,000 rows -> test AUC 0.778M1. Why is accuracy a poor metric here?
Because 22.1% of clients defaulted, a model that predicts "no default" for everyone is 77.9% accurate and catches no defaulters at all, a recall of 0. Any accuracy figure must be compared with that baseline. For imbalanced problems, report ROC AUC or precision and recall, and say which errors cost more.
M2. What do overfitting and underfitting look like?
Growing a decision tree deeper showed both. At depth 2, training and test AUC were close, 0.695 and 0.690: the model was too simple to learn much, which is underfitting. Depth 5 gave the best test AUC, 0.747. By depth 20 the training AUC was 0.974 but the test AUC had fallen to 0.599, and an unlimited tree scored a perfect 1.000 on training data. That growing gap between training and test is overfitting: the tree learned individual clients rather than patterns (scikit-learn: decision trees). It is the bias-variance trade-off in one table.
M3. What does L1 regularisation do that L2 does not?
L1 can set coefficients to exactly zero, so it selects features (scikit-learn: linear models). With logistic regression, stronger regularisation, a smaller C, cut the features in use from 19 to 14 with the same test AUC of 0.711, and then to 2 at a cost: AUC fell to 0.692. Fourteen features did the work of nineteen, which makes a simpler and more stable model. L2 shrinks coefficients towards zero but keeps them all, which suits groups of correlated features.
M4. Why is 0.5 not always the right threshold?
The model outputs a probability; the threshold turns it into a decision, and scikit-learn's default of 0.5 is only a convention (scikit-learn: decision threshold). The random forest's ranking, AUC 0.778, stayed fixed while the threshold moved. At 0.5 it flagged 11.3% of clients and caught 34.6% of defaulters, with 67.5% precision. At 0.2 it flagged 36.2% and caught 67.9%, but only 41.5% of those flagged went on to default. Which is right depends on the cost of a missed default against the cost of reviewing or refusing a good client. That is a business question, and saying so is part of the answer.
M5. What is calibration, and when does it matter?
A model is calibrated if, among clients given a probability of about 0.5, about half default (scikit-learn: calibration). In the riskiest fifth of clients, the forest predicted 0.55 and 56% defaulted, which is well calibrated. Logistic regression predicted 0.46 where 54% defaulted, under-stating the risk. Calibration matters when probabilities are used as numbers, for pricing, expected loss or capacity planning, and not just for ranking. The Brier score, 0.135 against 0.147, summarises the same comparison.
M6. How much should you trust one validation score?
Less than one number suggests. Five-fold cross-validation gave an AUC of 0.781 with a standard deviation of 0.010, and individual folds ranged from 0.765 to 0.793. A single train-test split could have reported anything in that range. Report the spread, and treat two models whose scores differ by less than it as tied.
M7. Would more data help?
A learning curve answers this. The forest scored 0.753 with 500 training rows, 0.766 with 2,000, 0.771 with 8,000 and 0.778 with all 21,000. The curve is flattening: each fourfold increase gained less than the one before. More rows of the same kind will help only a little; better features, such as trends in the payment history, are more likely to move the score.
How to answer concept questions
- Start with the definition, then give the evidence: "here is what happened when I did it".
- Name the baseline for every metric.
- Separate ranking from decisions: the model ranks, the threshold decides.
- Report spread, not only averages.
Each of these concepts has a longer treatment: cross-validation in machine learning, handling imbalanced datasets and an end-to-end machine learning project. Feature questions are in feature engineering interview questions, and the full round in data science interview questions and answers.
What machine learning concepts are asked most in interviews?
How do I explain overfitting in an interview?
What is the difference between L1 and L2 regularisation?
Should I remove sensitive attributes from a model?
These concepts are taught hands-on in the Data Science course.
Sources
- Default of Credit Card Clients dataset (UCI Machine Learning Repository) — UCI Machine Learning Repository
- Decision Trees (scikit-learn documentation) — scikit-learn
- Tuning the decision threshold for class prediction (scikit-learn documentation) — scikit-learn
- Probability calibration (scikit-learn documentation) — scikit-learn
- Linear Models (scikit-learn documentation) — scikit-learn
GloryTecks Team
Training & Placement Faculty
The GloryTecks faculty team mentors learners across Data Science, AI and Data Engineering, with a focus on real-time projects and placement readiness in Hyderabad.
Want to master Interview Questions?
Join GloryTecks’ expert-led Data Science training in Hyderabad with real-time projects and 100% placement support.
Related articles
SQL Interview Questions: Top 50 with Answers
Fifty SQL interview questions with answers checked on PostgreSQL, DuckDB and SQLite against one small practice schema: evaluation order, NULL logic, joins and fan-out, window functions, dates, and performance, including where the three engines disagree.
Python Interview Questions for Data Roles
The plain-Python coding tasks data-analyst and data-engineer interviews use, without pandas: counting, deduplicating, grouping, streaming large files, flattening JSON, joining, and the bugs interviewers plant. Each has a worked solution and the follow-up questions to expect.
Data Science Interview Questions and Answers 2026
A data science interview is several interviews in one: statistics, machine learning, coding, product sense and a take-home. This guide maps each round with model answers, then works a churn take-home on real telecom data, including the checks that separate a strong submission from a high score.