Skip to content

Feature Engineering Interview Questions for Data Science

32 Feature Engineering questions with answers for data science roles — 9 easy, 17 medium, 6 hard.

About Feature Engineering

Feature engineering questions test how you turn raw data into useful model inputs: encoding categoricals, handling skew and outliers, dates, text and location features, aggregations and time-aware features. Interviewers focus on leakage and training-serving skew, because these silently break models. Good features often matter more than the choice of algorithm, so this topic carries real weight.

Sheet progressStart 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

What is data leakage?

Save to ▾
Show answer
Information from outside the training window, such as future data or test statistics, enters training and inflates performance. Split first, then fit scalers and encoders on training data only.
02

What is the difference between one-hot, label and ordinal encoding?

Save to ▾
Show answer
One-hot encoding creates a binary column per category and suits nominal data like city for linear models. Label encoding maps categories to integers arbitrarily; it is fine for tree models but implies a false order for linear models. Ordinal encoding also uses integers but in a meaningful order, like low, medium, high mapped to 0, 1, 2. Choose based on whether categories have a natural order and which model you use.
03

Write Pandas code to create useful features from a datetime column.

Save to ▾
Show answer
df['ts'] = pd.to_datetime(df['ts']) df['hour'] = df['ts'].dt.hour df['dayofweek'] = df['ts'].dt.dayofweek df['is_weekend'] = df['dayofweek'].isin([5, 6]).astype(int) df['month'] = df['ts'].dt.month df['days_since_signup'] = (df['ts'] - df['signup_date']).dt.days
04

What is binning and when is it useful?

Save to ▾
Show answer
Binning groups a continuous variable into ranges, like age into 18-25, 26-35 and so on. It can capture non-linear effects in linear models, reduce the impact of outliers and make results easier to explain to business teams. Bins can be equal width, equal frequency using quantiles, or chosen by domain knowledge. The downside is losing information inside each bin, and tree models usually do not need it.
05

Why do you apply a log transform to some features?

Save to ▾
Show answer
A log transform compresses large values and spreads small ones, which reduces right skew in features like income, price or page views. This helps linear models and distance-based models that are sensitive to scale and outliers. Use log1p, which is log of 1 plus x, when the feature has zeros. For negative values, a Yeo-Johnson transform works. Tree models generally do not need it.
06

How do you handle rare categories in a categorical feature?

Save to ▾
Show answer
Categories that appear only a few times give unreliable signals and create many sparse columns. A common fix is to group all categories below a frequency threshold, like 1 percent, into an Other bucket. You can also use frequency encoding or smoothed target encoding. Make sure the encoder handles unseen categories at prediction time, for example with handle_unknown set to ignore.
07

Write Pandas code to encode hour of day as a cyclical feature.

Save to ▾
Show answer
import numpy as np # hour 23 and hour 0 should be close, so use sin and cos df['hour_sin'] = np.sin(2 * np.pi * df['hour'] / 24) df['hour_cos'] = np.cos(2 * np.pi * df['hour'] / 24)
08

Write Pandas code to cap outliers at the 1st and 99th percentile.

Save to ▾
Show answer
# fit limits on training data only, then apply to test low, high = train['income'].quantile([0.01, 0.99]) train['income_capped'] = train['income'].clip(low, high) test['income_capped'] = test['income'].clip(low, high)
09

In production your model receives category values, like a new payment method, that never appeared in training. What happens and how do you handle it?

Save to ▾
Show answer
Depending on the encoder, the pipeline may crash or silently map the value to all zeros. Plan for it: use OneHotEncoder with handle_unknown='ignore' or map unseen values to an explicit 'other' bucket that also exists in training for rare values. Log and monitor the rate of unknown categories, since a rising rate signals data drift, and retrain when new categories become common.
10

How do you perform feature selection?

Save to ▾
Show answer
Use filter methods (correlation, chi-square), wrapper methods (RFE), embedded methods (Lasso, tree importance) and domain knowledge, validating each choice with cross-validation.
11

What is feature scaling and which models need it?

Save to ▾
Show answer
Putting features on comparable ranges using standardisation or min-max scaling. Distance-based and gradient-based models (KNN, SVM, regression, neural nets) need it; tree models do not.
12

How do you deal with high-cardinality categorical features?

Save to ▾
Show answer
Use target or frequency encoding with cross-validation, hashing, embeddings or grouping rare categories, instead of huge one-hot matrices.
13

You target-encoded a city column and validation AUC jumped from 0.72 to 0.95. What do you suspect?

Save to ▾
Show answer
Target encoding replaces each category with the average target value for that category, for example the churn rate per city. It handles high-cardinality columns compactly. The main risk is leakage: if a row's own target is included in its encoding, the model sees the answer and overfits. Prevent it with out-of-fold encoding, smoothing toward the global mean for rare categories, and fitting only on training data.
14

Write Pandas code to create lag and rolling features for each customer.

Save to ▾
Show answer
df = df.sort_values(['customer_id', 'month']) g = df.groupby('customer_id')['spend'] df['spend_lag1'] = g.shift(1) df['spend_lag3'] = g.shift(3) # shift first so the current month is not included df['spend_roll3_mean'] = g.transform(lambda s: s.shift(1).rolling(3).mean())
15

What are interaction features and when do they help?

Save to ▾
Show answer
Interaction features combine two or more variables, such as price times quantity, or income divided by number of dependents. They help linear models capture effects where one variable changes the impact of another. Tree models can learn some interactions themselves, but explicit ratios often still help. Too many automatic interactions explode the feature count and overfit, so build them from domain logic and validate each one.
16

Your model's most important feature is customer_id. What is wrong?

Save to ▾
Show answer
An ID has no real meaning, so high importance means the model is memorising individual customers. It often happens when the same customers appear in both train and test, or when IDs were assigned in time order and act as a proxy for date or signup cohort. I would drop the ID, use a group-based split by customer, and if timing matters, add an explicit feature like account age instead.
17

How do you turn text columns into features for a tabular model?

Save to ▾
Show answer
Simple options are length, word count and keyword flags. TF-IDF vectors capture important words and work well with linear models. For meaning, use sentence embeddings from a pretrained model and optionally reduce them with PCA. You can also train a separate text classifier and feed its predicted score as one feature. Fit any vocabulary or encoder on training data only to avoid leakage.
18

Write a scikit-learn ColumnTransformer that preprocesses numeric and categorical columns.

Save to ▾
Show answer
from sklearn.compose import ColumnTransformer from sklearn.pipeline import make_pipeline from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler, OneHotEncoder pre = ColumnTransformer([ ('num', make_pipeline(SimpleImputer(strategy='median'), StandardScaler()), num_cols), ('cat', make_pipeline(SimpleImputer(strategy='most_frequent'), OneHotEncoder(handle_unknown='ignore')), cat_cols) ]) model = make_pipeline(pre, LogisticRegression(max_iter=1000))
19

What is recursive feature elimination?

Save to ▾
Show answer
Recursive feature elimination trains a model, ranks features by importance or coefficient size, removes the weakest ones, and repeats until the desired number remains. RFECV picks the number of features using cross-validation. It considers features together rather than one at a time. The downsides are high compute cost on large data and unstable results when features are correlated, so check stability across folds.
20

How would you build RFM features for a customer churn model?

Save to ▾
Show answer
RFM stands for recency, frequency and monetary value. From the transactions table, for each customer as of a cut-off date: recency is days since the last purchase, frequency is the number of orders in the last 90 days, and monetary is total or average spend in that window. Compute them using only data before the cut-off, add trends like spend this month versus last, and the label from the period after.
21

How do you work with domain experts to find good features?

Save to ▾
Show answer
Situation: on an insurance claims model, my first features gave average results. Task: improve fraud detection. Action: I sat with two claim investigators for a day and asked what made them suspicious. They mentioned claims filed soon after policy start and repeated garage names. I turned these into features and checked them with the team. Result: recall at the same precision rose by 12 points. Experts often know signals the data hides.
22

Write Python code to compute the haversine distance between customer and store locations.

Save to ▾
Show answer
import numpy as np def haversine_km(lat1, lon1, lat2, lon2): lat1, lon1, lat2, lon2 = map(np.radians, [lat1, lon1, lat2, lon2]) dlat, dlon = lat2 - lat1, lon2 - lon1 a = np.sin(dlat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2 return 6371 * 2 * np.arcsin(np.sqrt(a)) df['dist_km'] = haversine_km(df.cust_lat, df.cust_lon, df.store_lat, df.store_lon)
23

After one-hot encoding you have 2,000 features and training is slow. What do you do?

Save to ▾
Show answer
Find which columns caused the explosion, usually a few high-cardinality categoricals. Group rare categories into Other, or switch those columns to frequency, target or hashing encoding. Use sparse matrices so zeros take no memory. Tree libraries like LightGBM and CatBoost can handle categoricals natively without one-hot. Then remove near-constant columns and check that validation scores hold up with the smaller feature set.
24

Tell me about a feature you engineered that significantly improved a model.

Save to ▾
Show answer
Situation: our delivery time model kept underestimating late-night orders. Task: reduce large errors. Action: I noticed restaurant prep time depended on how busy the kitchen was, so I built a feature for active orders at that restaurant in the last 30 minutes, computed point in time. Result: MAE dropped by 14 percent and late-night errors fell the most. It taught me to study the worst errors before adding generic features.
25

What are polynomial features and what is the risk of using them?

Save to ▾
Show answer
Polynomial features add powers and products of existing features, like x squared and x times y, so a linear model can fit curves and interactions. The risk is that the number of features grows very fast with degree and input count, causing overfitting, slow training and multicollinearity. Use a low degree, scale features first, and add regularisation such as Ridge or Lasso to keep coefficients under control.
26

What are quantile and power transforms such as Box-Cox and Yeo-Johnson, and when do you use them?

Save to ▾
Show answer
Power transforms reshape a skewed feature to look more normal. Box-Cox needs strictly positive values, while Yeo-Johnson also handles zero and negative values; both learn a lambda parameter from training data. A quantile transform maps values to a uniform or normal distribution by rank, which is robust to outliers. They help linear models, distance-based methods and neural networks, but tree models rarely need them.
27

What is multicollinearity and how do you handle it?

Save to ▾
Show answer
Predictors that are highly correlated make coefficients unstable. Detect with VIF above about 5-10, then drop or combine features, use PCA or apply regularisation.
28

You need to use a device_id column with millions of unique values in a streaming model. How would feature hashing help?

Save to ▾
Show answer
Feature hashing, the hashing trick, maps categories or tokens into a fixed number of columns using a hash function, without storing a vocabulary. It handles very high-cardinality or ever-changing values, like URLs or device IDs, with constant memory and works well in streaming systems. The trade-off is collisions, where different values share a column, and the features cannot be reversed for explanation. Choose a large enough number of buckets.
29

A feature works well offline but is not available at prediction time in production. How do you handle this?

Save to ▾
Show answer
This is training-serving skew. The feature might be computed from data that arrives later, like final order status. First confirm exactly when each feature is available in production. Rebuild the training set using point-in-time values, as they were at prediction time, or drop the feature. A feature store with point-in-time joins and the same feature code for training and serving prevents this. Expect offline scores to drop, but they become honest.
30

How do you engineer features for a time series forecast without leaking future information?

Save to ▾
Show answer
Every feature must use only data available before the forecast time. Use lags and rolling windows that shift past the current point, and respect the forecast horizon: for a 7-day-ahead forecast, the most recent usable lag is 7 days. Compute scalers and encodings inside each training fold. Use known-future features only when truly known, like holidays or planned promotions. Validate with rolling-origin backtests that mimic production.
31

Tree feature importance ranks an ID-like numeric column near the top. Why, and which importance method would you trust instead?

Save to ▾
Show answer
Impurity-based importance, the default in tree models, sums how much each feature reduces impurity across splits. It is fast but biased toward high-cardinality and continuous features, and it is computed on training data. Permutation importance shuffles one feature at a time on validation data and measures the drop in score, so it reflects real predictive value. Both can understate correlated features, because the model can lean on the copy.
32

Write Pandas code to compute each customer's average order value excluding the current order.

Save to ▾
Show answer
g = df.groupby('customer_id')['amount'] total = g.transform('sum') count = g.transform('count') # Leave-one-out mean; NaN when it is the customer's only order df['avg_other_orders'] = (total - df['amount']) / (count - 1) df.loc[count == 1, 'avg_other_orders'] = float('nan') # For time-aware features, use only earlier orders instead

Frequently asked questions

How important is Feature Engineering in Data Science interviews?

Feature engineering questions test how you turn raw data into useful model inputs: encoding categoricals, handling skew and outliers, dates, text and location features, aggregations and time-aware features. Interviewers focus on leakage and training-serving skew, because these silently break models. Good features often matter more than the choice of algorithm, so this topic carries real weight.

How should I use the Feature Engineering sheet?

Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.