When I was hiring a junior data scientist at Blackstraw, I used a short interview in two parts: a 20-minute hands-on exercise in a notebook, then a set of theory questions. None of it is hard. The goal is to check the basics and see how the candidate thinks.
The questions and notebook are on GitHub: Zilch123/Data-Science-Interview
What I’m actually looking for
Getting every answer right matters less than three things:
- Curiosity. Do they ask about the data, the problem or the business before jumping in?
- Clarifying questions. “Optimise for recall” is vague on purpose. A good candidate asks what it means here before writing code.
- Talking through their thinking. I want to hear why they’re doing something, not just watch them type. A wrong answer explained clearly tells me more than a right answer in silence.
Part 1: the hands-on exercise
The data is scikit-learn’s breast cancer dataset: 569 samples, 30 numeric features, and two classes, benign and malignant. Malignant is the positive class (1).
from sklearn import datasets
import pandas as pd
dat = datasets.load_breast_cancer()
df = pd.DataFrame(dat.data, columns=dat.feature_names)
df['target'] = [1 if t == 0 else 0 for t in dat.target] # malignant = 1Q2. For the top five, what’s the difference between benign and malignant, with tolerance? (8 min)
“With tolerance” means: don’t just give me the means, show me the spread as well.
top = ['mean perimeter', 'worst radius', 'mean concave points',
'worst perimeter', 'worst concave points']
df.groupby('target')[top].agg(['mean', 'std'])| Feature | Benign (mean ± std) | Malignant (mean ± std) |
|---|---|---|
| mean perimeter | 78.1 ± 11.8 | 115.4 ± 21.9 |
| worst radius | 13.4 ± 2.0 | 21.1 ± 4.3 |
| mean concave points | 0.026 ± 0.016 | 0.088 ± 0.034 |
| worst perimeter | 87.0 ± 13.5 | 141.4 ± 29.5 |
| worst concave points | 0.074 ± 0.036 | 0.182 ± 0.046 |
Answer: malignant tumours are clearly larger and have more concave points, and the gaps are bigger than the standard deviations, so the classes separate well. Strong candidates plot the distributions, or mention a test like a t-test, instead of stopping at the table.
Q3. Build a logistic regression model optimised for recall. (10 min)
Recall matters here because missing a malignant tumour is much worse than a false alarm.
A plain LogisticRegression() on an 80/20 split already gets 0.98 recall and 0.88 precision on malignant cases. Most candidates stop there. A stronger answer:
- scales the features (logistic regression is sensitive to scale)
- uses a stratified split
- tunes
Cwith recall as the scoring metric - picks the probability threshold on purpose, instead of using the default 0.5
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_predict
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import precision_recall_curve, classification_report
X, y = df.drop(columns='target'), df['target']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=0)
pipe = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
grid = GridSearchCV(pipe,
{"logisticregression__C": [0.01, 0.1, 1, 10],
"logisticregression__class_weight": [None, "balanced"]},
scoring="recall", cv=5)
grid.fit(X_train, y_train)
# out-of-fold probabilities, so the threshold isn't tuned on data the model has seen
probs = cross_val_predict(grid.best_estimator_, X_train, y_train,
cv=5, method="predict_proba")[:, 1]
precision, recall, thresholds = precision_recall_curve(y_train, probs)
threshold = thresholds[recall[:-1] >= 0.98].max() # highest threshold with recall >= 0.98
y_pred = (grid.predict_proba(X_test)[:, 1] >= threshold).astype(int)
print(classification_report(y_test, y_pred))On my run this gave 0.98 recall and 0.79 precision on the test set. That’s the trade-off: higher recall costs precision. The interesting part of the conversation is how they’d decide where to set it, and whether they ask the clinician or business side what a missed case costs.
Part 2: theory questions
Approaches for imbalanced datasets?
- Use the right metric: precision, recall, F1 or PR-AUC, not accuracy.
- Resample: oversample the minority class (for example with SMOTE) or undersample the majority. Do it on the training set only.
- Use class weights, so mistakes on the minority class cost more.
- Tune the decision threshold.
- Use stratified splits, so every fold has some minority examples.
- Get more minority data if you can.
Your preprocessing and inference take 6 minutes in production. The MLOps team wants it real-time. What do you suggest?
The best first answer is “find out where the 6 minutes go”. Profile before changing anything. Common fixes:
- Precompute heavy features offline and look them up at request time (a feature store or cache).
- Load the model once at startup, not on every request.
- Replace Python loops with vectorised pandas or NumPy code.
- Use a smaller or faster model, or quantise or distil the current one.
- Split the work: run what has to be live in real time and batch the rest.
- Scale out horizontally if it’s a throughput problem rather than latency.
What are precision and recall? When do you prioritise recall?
- Precision: of everything predicted positive, how much was actually positive? TP / (TP + FP).
- Recall: of everything actually positive, how much did we find? TP / (TP + FN).
Prioritise recall when missing a positive is expensive: cancer screening, fraud detection or safety faults. Prioritise precision when false alarms are expensive, like spam filters that bin real email.
When do you use the F1 score?
F1 is the harmonic mean of precision and recall. Use it when you care about both, want a single number to compare models, and the classes are imbalanced. It’s low if either precision or recall is low.
When shouldn’t you use accuracy?
When classes are imbalanced. If 1% of transactions are fraud, a model that always says “not fraud” is 99% accurate and completely useless. Accuracy also treats every mistake as equally costly, which is rarely true.
What is regularisation, and when do you use it?
Regularisation adds a penalty on model weights to the loss, so the model prefers simpler solutions and overfits less.
- L1 (lasso) can push weights to exactly zero, so it also does feature selection.
- L2 (ridge) shrinks all weights smoothly and handles correlated features well.
Use it when the model overfits (good on training data, worse on validation), when you have many features or few samples, or when features are correlated. In scikit-learn’s LogisticRegression, C is the inverse of the regularisation strength, which candidates often get backwards.
How do you compare two distributions?
- Start visually: histograms, density plots, box plots or a QQ plot.
- Use a test that fits the question: Kolmogorov-Smirnov for the whole distribution, a t-test or Mann-Whitney U for the centre, chi-square for categories.
- For data drift in production, use KL or Jensen-Shannon divergence, or the population stability index (PSI).
What is A/B testing?
A controlled experiment. You randomly split users into two groups, show each a different version, and compare a metric you chose beforehand, like conversion rate. Decide the metric, sample size and duration up front, then use a significance test at the end. The classic mistake is checking the results every day and stopping as soon as they look good.
What types of recommender systems are there?
- Collaborative filtering: recommends from user behaviour (“people who liked this also liked…”). It can be user-based, item-based, or use matrix factorisation.
- Content-based: recommends items similar to what the user already liked, using item features.
- Hybrid: combines the two, which helps with the cold-start problem for new users and items.
A popularity-based recommender is a useful baseline to beat.
How does gradient descent work?
It minimises a loss function step by step. At each step, compute the gradient of the loss with respect to the parameters, and move the parameters a small amount in the opposite direction. The step size is the learning rate: too big and it overshoots or diverges, too small and it’s slow. Batch gradient descent uses all the data for each step, stochastic uses one sample, and mini-batch (the usual choice) uses a small batch.
How do PCA and SVD work?
PCA finds new axes (principal components) that capture the most variance in the data. Each one is at right angles to the previous ones. Keeping the first few reduces the number of dimensions while losing as little information as possible.
In practice, PCA is computed with SVD. Centre the data and factor it as X = UΣVᵀ. The columns of V are the principal components, and the singular values in Σ tell you how much variance each one explains. Scale the features first, or the ones with large units will dominate.