Feature Engineering Interview Questions — Data Science Practice Quiz
Reviewed by Mark Dickie · Last updated
4 questions on this page you can answer and see marked on the spot. Go to the first one
Feature engineering is the process of transforming raw data into inputs that a machine learning model can learn from effectively. For interviews, you are expected to know how to encode categorical variables, scale or transform numeric features, handle missing values, create interaction terms, and avoid data leakage. These skills come up in both take-home challenges and whiteboard rounds because they test whether you can turn messy real-world data into something a model can actually use.
What does a feature engineering interview typically test?
Interviewers focus on practical decisions: which encoding suits a high-cardinality categorical column, when to apply log transforms, how to bin continuous variables without losing signal, and how to detect leakage before it inflates your validation scores. You may also be asked to justify a choice in plain language: why one-hot encoding here, why target encoding there, why standardization versus min-max scaling for a given algorithm.
| Concept | Common Interview Angle | Example Question |
|---|---|---|
| Categorical encoding | Cardinality vs. dimensionality trade-off | "When would you prefer target encoding over one-hot?" |
| Numeric scaling | Algorithm sensitivity to feature ranges | "Why does KNN need scaled features but tree models do not?" |
| Missing values | Imputation strategy and its risks | "What goes wrong if you impute using the full dataset before splitting?" |
| Interaction features | Capturing non-additive effects | "How would you build a feature that captures the interaction between price and season?" |
| Data leakage | Train/test separation at every step | "Where in your pipeline can leakage creep in?" |
How should you prepare for feature engineering questions?
- Build a personal checklist of encoding methods (one-hot, ordinal, frequency, target, embedding) and when each one breaks down.
- Practice scaling and transformation choices against specific algorithms so you can explain the reasoning, not just the code.
- Work through a full pipeline on a messy dataset and write down every point where leakage could enter: imputation, feature selection, target encoding, cross-validation folds.
- Study interaction-term design and polynomial features so you can articulate when added complexity helps and when it just adds noise.
- Review time-series-specific feature engineering (lag features, rolling windows, differencing) since it appears in many data science roles and has its own leakage pitfalls.
Key facts
- Tarmac has 15 Data Science interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 917 job postings asking for Data Science in September 2026.
- Roles asking for Data Science advertise a median base salary of US$167,950, across 283 job postings as of September 2026.
- Tarmac last reviewed these Data Science interview questions on 19 October 2026.
At a glance
| Questions | 10 shown · 15 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Ordering, Multiple answer, Code output, True / false, Find the bug, Short answer, Fill in the blank, Flashcard, Coding exercise |
| Interactive | 1 run your code against tests, in the app |
What you'll review
- encoding categorical features
- feature selection importance
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
You are preparing a feature for a linear regression model. The column color is a nominal feature with three values: red, green, and blue, and there is no natural order among them. Which encoding is the most appropriate choice?#
Options
Show answer
One-hot encoding is the standard choice for nominal categorical features such as color in linear models. It creates one binary column per category, so no artificial ordering or spacing is imposed. Integer label encoding would make a linear model treat blue as twice green, which is meaningless for unordered categories.
Color has no inherent order, so the encoding must not introduce one. One-hot encoding creates a separate 0/1 indicator column for each color, letting the model learn an independent effect for each category. Mapping the colors to integers (red=0, green=1, blue=2) would force a linear model to treat them as ordered and equally spaced, which is a false assumption. Ranking by frequency still imposes an arbitrary order, and min-max scaling cannot be applied to non-numeric strings in a meaningful way.
Put these steps of a filter-based feature selection workflow in the correct order, from first to last.#
Put these in order
Show answer
The correct order is to split the data into training and test sets first, then score each feature using only the training rows, keep the top-k features, and finally retrain and evaluate on the test set. Splitting first keeps test-set information out of feature selection, so the final performance estimate is not inflated by leakage.
The split must come first so that every later step that looks at the target, including feature scoring, sees only training rows; otherwise test information leaks into the choice of features and inflates the measured performance. Scoring must precede selection because the top-k cut needs the scores. Selection must precede retraining because the model should be fit only on the chosen features. The held-out test set is used last, once, to estimate performance of the final pipeline.
You are encoding a nominal categorical feature (for example, city, with no natural order) for a linear regression model. Compared with mapping each category to an integer code, which of the following statements about one-hot encoding are true? Select all that apply.#
Options
Pick every one that applies.
Show answer
One-hot encoding avoids imposing an arbitrary numeric order on nominal categories, and it lets a linear model assign each category its own coefficient. It does not keep the feature to one column, since columns grow with cardinality, and it does not prevent overfitting to rare categories.
One-hot encoding creates one binary indicator per category, so no integer ordering is implied and a linear model can weight each category independently; those two statements are correct. It does not collapse the feature to one column: a feature with k categories becomes k columns (or k-1 when one is dropped to avoid collinearity), so the width grows with cardinality. It also gives no guarantee against overfitting, since rare categories yield indicator columns with very few non-zero rows that a model can still fit to noise.
A feature-selection helper keeps a feature only if at most 40% of its values are missing AND it has more than one distinct non-missing value (a constant feature carries no information). What does the following Python program print?#
features = {
"age": [25, 32, None, 41, 29],
"income": [50, 50, 50, 50, 50],
"zip": [1, None, None, 3, None],
"score": [7, 3, 9, 1, 5],
}
def select(features, max_missing=0.4):
kept = []
for name, col in features.items():
missing = sum(v is None for v in col) / len(col)
values = {v for v in col if v is not None}
if missing <= max_missing and len(values) > 1:
kept.append(name)
return kept
print(select(features))Show answer
['age', 'score']
The program walks the dictionary in insertion order. "age" has 1 missing out of 5 (0.2 ≤ 0.4) and four distinct values, so it is kept. "income" has no missing values but only one distinct value (50), so it is dropped as constant. "zip" has 3 missing out of 5 (0.6 > 0.4), so it is dropped for excess missingness. "score" has no missing values and five distinct values, so it is kept. The returned list is therefore ['age', 'score'], which the print statement displays with Python's list repr.
True or false: If you target-encode a categorical feature by computing each category's mean label over the entire training set (including the rows you will later hold out as validation folds) before running k-fold cross-validation, the resulting CV score can be optimistically biased.#
Options
Show answer
True. Computing target-encoding means over the whole training set before cross-validation leaks validation-fold labels into the features. Each row's own label then influences its encoded value, so CV scores are optimistically biased. Encode within each training fold to avoid this.
The statement is true. When category means are computed over all training rows before splitting, each validation row's own label contributes to the encoding of its category, and validation-fold labels shape the feature values the model is trained on. This is target leakage: the feature carries information about the labels it is supposed to predict, so the CV estimate overstates real performance on unseen data. The fix is to compute the encoding inside each fold using only that fold's training rows (or use out-of-fold/nested target encoding), so validation labels never influence the features used to score them.
A data scientist wants to estimate how well a logistic regression model generalizes after keeping only the 10 features most associated with the label. X is a 1000x50 NumPy feature matrix and y is a binary label array. Which line is the bug? Report the 1-based line number.#
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
selector = SelectKBest(score_func=f_classif, k=10)
X_selected = selector.fit_transform(X, y)
X_train, X_test, y_train, y_test = train_test_split(X_selected, y, test_size=0.2, random_state=0)
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
print(model.score(X_test, y_test))Show answer
The bug is on line 7.
Line 7 calls fit_transform on the selector using the full dataset X and the full label vector y before the train/test split. The ANOVA F-scores used to choose the 10 features are therefore computed using the labels of the rows that will later be held out as the test set, so the test data has influenced feature selection. This leaks information and tends to inflate the reported test accuracy. The fix is to split first and fit the selector only on X_train and y_train, then apply the fitted selector to X_test. Lines 1 through 6 and lines 8 through 11 are not the defect: the imports, the selector construction, the split call, and the model fit and scoring are correct in themselves.
You are building a churn classifier with a high-cardinality feature zip_code (about 40,000 levels, many with fewer than 5 training rows). You plan to replace each zip code with the mean churn rate for that zip, computed over the full training set, and then run 5-fold cross-validation on the encoded data. Explain why the cross-validation estimate will be optimistic, and describe two concrete changes that make the encoding honest and also handle the rare zip codes.#
Show answer
The encoding is fit on the full training set, so every row's encoded value includes its own label (and the labels of its validation fold). The feature therefore leaks the target into the validation folds, and the CV score is inflated. For a zip with one or two rows, the encoded value almost equals the row's own label, so the model looks far better than it will on unseen data. Fixes: (1) Compute the target encoding inside each training fold only (out-of-fold or nested within the pipeline), and apply the learned mapping to the validation fold, so validation labels never influence its encoding. (2) Smooth the per-category mean toward the global churn rate, e.g. (ncategory_mean + mglobal_mean)/(n + m) with m chosen by validation, so rare zips shrink to the prior instead of producing extreme values. Unseen zips at prediction time should fall back to the global mean.
The core flaw is target leakage: the encoding for each row is computed from labels that include that row's own label and the validation fold's labels, so cross-validation rewards memorization of the encoding rather than generalization. Rare levels make this worst because a category with one or two rows encodes nearly the row's own label. The correct practice is to fit the encoder inside each training fold (or within a Pipeline used by cross-validation) and to smooth category means toward the global prior, which bounds the influence of small counts. Unseen categories at inference should map to the global mean.
A random forest's impurity-based importances (mean decrease in impurity) are computed from training-time splits and are biased toward high-cardinality features. To measure each feature's contribution on held-out data by shuffling one column at a time and recording the drop in model score, use _____ importance.#
Show answer
A random forest's impurity-based importances (mean decrease in impurity) are computed from training-time splits and are biased toward high-cardinality features. To measure each feature's contribution on held-out data by shuffling one column at a time and recording the drop in model score, use permutation importance.
Permutation importance shuffles one feature's values on held-out data, which breaks that feature's relationship with the target while leaving the rest of the model fixed. The resulting drop in score measures how much the model actually relies on that feature. Impurity-based importance, by contrast, is accumulated from split gains computed on training data, which favours features with many distinct values because they offer more possible split points to exploit. The blank therefore needs the term for shuffle-based importance, which is permutation importance.
In target encoding, why does replacing each row's categorical value with the mean target of that category, computed over the full training set including the row itself, leak the label? Describe precisely how out-of-fold target encoding removes this leak, including how the mapping is applied to validation or test rows.#
Show answer
The row's own label is included in the category mean that becomes its feature value, so the feature partially encodes the target. The leak is strongest for rare categories, where one row can dominate the mean, so a model learns a near-deterministic mapping that looks excellent on training data and fails on unseen data. Out-of-fold target encoding splits the training data into K folds; each row's encoding is the category mean computed only from the other K-1 folds, so its own label never contributes to its feature value. For validation and test rows, the mapping is fit on the full training set (typically with smoothing toward the global mean for rare categories) and applied without using any label from the rows being encoded.
The key internals point is that target encoding is a learned transformation, so fitting it on the same labels used for training makes the feature a function of the target for each row. Excluding the row's own label (via out-of-fold computation) breaks this self-reference, so the training-time feature distribution matches what the model sees at inference. Smoothing and fold-consistent statistics further control variance for rare categories. The answer is uniquely determined by the self-inclusion mechanism and its out-of-fold remedy.
You are screening m features with one p-value each (pvalues, a list of floats in the original feature order). Implement select_bh(pvalues, alpha) that applies the Benjamini-Hochberg procedure at false discovery rate alpha and returns the sorted list of original indices of the selected features.#
Starter code
def select_bh(pvalues, alpha):
m = len(pvalues)
order = sorted(range(m), key=lambda i: pvalues[i])
selected = []
for rank, i in enumerate(order, start=1):
if pvalues[i] <= rank * alpha / m:
selected.append(i)
else:
break
return sorted(selected)
Your solution must pass
- step-up: rank 1 fails but rank 2 passes
- no rank passes
This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.
Related interview questions
Job market
See data-science salaries and hiring demand from live job postings.
The other 5 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 5 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 marked answers per 30 days · written feedback on the paid plan