All questions
Showing of 58What is data leakage, and why does it wreck an otherwise good model?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Leakage means your training data contains information that would not exist at prediction time, or that quietly encodes the answer. The model learns that shortcut, because it is the easiest signal available.
The damage is that your offline numbers become fiction. Validation accuracy looks excellent, so you stop investigating and ship. In production the leaked column is empty, or it arrives after the decision, and performance collapses toward baseline.
It is hard to catch because nothing crashes. The code is correct; the data is wrong. A classic case is predicting fraud using a chargeback_filed column, when chargebacks only get filed after fraud is confirmed.
The cost is time and trust. Weeks of tuning on a leaked feature buy nothing, and business decisions get made on a number that was never true.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is feature engineering, and how much does it change model performance?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Feature engineering is the work of reshaping raw columns into inputs that expose structure the model can actually use. A raw timestamp is nearly useless; hour of day, day of week, and days since last order are not.
On tabular data the effect is large, usually larger than swapping model families. A gradient-boosted tree with well-built ratios and aggregates beats a heavily tuned network fed raw columns. Most real gains on structured problems come from the features.
The exception is domains where the model learns its own representation. For images, audio, and text, deep networks build features internally, so hand-crafted ones add little.
The cost is time and maintenance. Every engineered feature is code that must run identically in training and in serving, or the model sees something different once it is live.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Why does domain knowledge matter so much when you engineer features?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Domain knowledge tells you which combinations of columns mean something, and a blind search over raw columns cannot guess that. In card payments, transaction amount alone is weak. Amount divided by that customer's usual amount is strong.
It also tells you what exists at decision time. Someone who runs the process knows the risk score is written back two days later. That single fact prevents a leaked feature from ever being built.
It flags proxies too. Postcode often stands in for income or ethnicity, which matters for fairness and for stability when a neighborhood changes.
Without it, you brute-force thousands of combinations and hope a selection method sorts them out. That is slower, noisier, and produces features nobody can explain to the team relying on the prediction.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle categorical variables so a model can use them?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Models need numbers, so every category has to become one without inventing an order that is not there. Two questions decide the method: do the categories have a real ordering, and how many distinct values exist?
Few values and no order means one indicator column per value. Few values with a genuine order means integer codes that preserve it. Many values means grouping the long tail into "other", hashing, target statistics, or a learned embedding.
The model family matters as well. Trees split on integer codes without reading them as magnitudes, so they tolerate compact encodings. Linear and distance-based models read 3 as three times 1.
Whatever you pick, store the mapping as a fitted object rather than ad-hoc code. Serving must produce the same columns in the same order, or the model silently scores garbage.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is one-hot encoding, and how does it change your dataset's dimensionality?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
One-hot encoding replaces a categorical column with one binary column per distinct value; each row carries a single 1. A color column of red, green, and blue becomes three columns.
df["color"].nunique() # 3
pd.get_dummies(df, columns=["color"]).shape # (1000, 12), was (1000, 10)
Dimensionality grows with cardinality, not with row count. One column of k values costs k columns. Three columns of 100 values each add 300, and the resulting matrix is over 99 percent zeros.
That width costs memory and fit time, and it hurts trees in particular. A tree splits one column at a time, so a category spread across 100 binary columns needs depth to isolate. Sparse storage fixes the memory, not the depth. Past a few dozen values, reach for another encoding.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
When would you use ordinal encoding instead of one-hot encoding?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Reach for ordinal encoding when the categories have a genuine order and the model can exploit it. Low, medium, and high severity, education level, t-shirt sizes, and survey ratings all carry order that one-hot throws away.
Encoded as 1, 2, 3, the model can learn a single split at "greater than 2". One-hot would need several splits to express the same idea, and it treats each level as unrelated.
The second case is high cardinality feeding a tree model. Integer codes keep the frame narrow, and trees do not read the integers as magnitudes anyway.
The cost lands on linear and distance-based models. They assume the gap from 1 to 2 equals the gap from 2 to 3. If your order is invented, say country codes, you have handed the model a relationship that does not exist.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is feature scaling, and when is it essential?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Scaling puts numeric features onto comparable ranges so no feature dominates purely because of its units. Salary in the tens of thousands and age in the tens are not comparable until you fix that.
It is essential wherever the algorithm compares magnitudes across features. Distance-based methods like k-nearest neighbors and k-means, support vector machines, principal component analysis, and any model with a regularization penalty all qualify. Neural networks need it too.
The mechanism repeats each time. Distance sums squared differences, so the widest feature owns the result. A penalty applied per coefficient shrinks whichever features happen to use small units. Variance-maximizing methods follow units directly.
Tree-based models do not need it. The failure mode elsewhere is quiet: nothing errors, the model just ignores your small-scale features. Fit the scaler on training rows only.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between normalization and standardization?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Normalization usually means min-max scaling: subtract the minimum, divide by the range, landing every value between 0 and 1. Standardization subtracts the mean and divides by the standard deviation, giving mean 0 and spread 1 with no fixed bounds.
The practical split is bounds versus distribution. Min-max guarantees a range, which suits pixel values and network inputs that expect one. Standardization guarantees location and spread, which is what linear models and principal component analysis assume.
Neither changes the shape of the distribution. Standardizing a skewed column leaves it skewed; if you wanted symmetry, you need a log or power transform instead.
Min-max is the fragile one. A single extreme maximum squeezes every other value into a narrow band near zero, and the range you fitted on rarely holds for future data.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle missing values in a dataset?
What are the common ways to impute missing data, and when does each fit?
What is an outlier, and how does it distort your analysis and models?
How do you detect outliers in a dataset?
What is vectorization, and why is it preferred over looping in pandas?
What is the difference between loc and iloc, and when do at and iat help?
What are the three stages of a pandas groupby: split, apply, and combine?
What is the difference between merge, join, and concat in pandas?
What does an inner join do, and how do left, right, and outer differ?
How do you merge two DataFrames on multiple columns or on the index?
How do you prevent data leakage during preprocessing?
What are the main types of data leakage, and what does each look like?
Your model scores suspiciously well - how do you hunt for leakage?
How can feature engineering itself introduce data leakage?
How does a scikit-learn pipeline prevent leakage, and what does it not cover?
What is the difference between data leakage and overfitting?
How does target encoding leak the target, and what is the fix?
What is the dummy variable trap, and how do you avoid it?
Your city column has 50,000 unique values - how would you encode it?
A category appears at inference that training never saw - what do you do?
How do you choose a scaling method for a given model and dataset?
How does feature scaling affect gradient descent convergence?
Do random forests and gradient-boosted trees need feature scaling?
Your data has heavy outliers - how does that change your scaling choice?
With outliers present, should you impute with the mean or the median?
What do MCAR, MAR, and MNAR mean, and why does the difference matter?
How do KNN and iterative imputers differ from simple mean imputation?
A column is over 30% missing - do you impute it or drop it?
Once you have found outliers, how do you decide what to do with them?
What are the main families of feature selection methods, and how do they differ?
What are filter methods in feature selection, and when do they fit best?
What are wrapper methods, and how does recursive feature elimination work?
How do embedded methods like Lasso select features while the model trains?
What is the difference between feature selection and feature extraction?
How should a feature's correlation with the target guide your selection?
Given size and rooms in housing data, how would you build interaction features?
How would you engineer features from customer purchase history to predict churn?
How do you apply several aggregation functions at once to grouped data?
Two DataFrames share a non-key column name - what does merge do?
What causes SettingWithCopyWarning in pandas, and how do you fix it?
What is the difference between a shallow and a deep copy in pandas?
What is broadcasting in NumPy, and when do two shapes fail to align?
When do you reach for map, apply, or applymap in pandas?
What does data leakage look like in a time-series model?
In production, what happens to values outside the range the min-max scaler saw?
How would you engineer time-based features to catch fraudulent transactions?
How do views and copies differ in pandas, and why does chained indexing break?
What does Copy-on-Write change in pandas 3.0, and why was it introduced?
What is the difference between apply and transform inside a groupby?
How would you speed up a merge between two very large DataFrames?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Data Preparation & Feature Engineering cheatsheet
- 30-second mental model01
- Stop data leakage02
- Encode categorical columns03
- Scale numeric features04
- Fill missing values05
- Deal with outliers06
- Build features that pay07
- Select features08
- pandas: get the right rows and columns09
- pandas: group and aggregate10
- pandas: combine frames11
- pandas: make it fast12
- + 1 more inside
- + 7 more inside
50 of 58 Data Preparation & Feature Engineering answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.