# Feature engineering and data preparation

> What interviewers check on Feature engineering and data preparation, and what to study, in order.

Canonical: https://saadho.arushk.tech/topics/feature-engineering
Last updated: 2026-10-26

ML fundamentals. Asked in most interview loops. About 2 h 30 min to learn. 3 vetted resources.

## What this topic covers

Turning raw columns into inputs a model can learn from, without letting information from the test set or the future leak in. That means handling missing values (drop, impute or flag), encoding categoricals (one-hot, hashing or target encoding), scaling numeric features for the models that care about scale, and dealing with class imbalance. It also means splitting data the way the model will be used: by time when it predicts the future, and by user or group when the same entity appears in many rows. Interviewers check that you fit every preprocessing step on the training data only, spot leakage in a described pipeline, choose an encoding for a high-cardinality feature, and know which models need scaled inputs.

## You’re ready when you can

- Choose between linear scaling, Z-score scaling, log scaling and clipping for a given feature distribution
- Explain one-hot encoding, how to handle out-of-vocabulary values and what to do when the vocabulary is huge
- Describe downsampling and upweighting for an imbalanced dataset, and why the upweighting is needed
- List what makes a test set trustworthy, including no duplicates of training examples
- Explain why scaling or feature selection fitted on the full dataset before splitting inflates validation scores
- Show how a Pipeline keeps preprocessing inside each cross-validation fold
- Explain why test data must never be passed to fit or fit_transform
- Explain what goes wrong when training and test data go through different transformations
- Choose a split for time-ordered data and for data with many rows per customer
- Explain which steps must happen inside resampling to avoid information leakage

## Feature engineering and data preparation interview questions

**How would you encode a categorical feature with thousands of distinct values?**

- One-hot encoding creates a sparse column per category, which suits linear models with a modest vocabulary but grows huge here and leaves rare categories with too few examples to learn from.
- Group rare categories into an “other” bucket, hash values into a fixed number of buckets and accept some collisions, or learn an embedding when a neural network consumes the feature.
- Target encoding replaces each category with a smoothed mean of the label, but it must be fitted out of fold or on separate data, or it leaks the label and overfits.

**Only 1% of your training examples are positive; what would you change in how you train the model?**

- First check whether the minority class has enough examples to learn from at all; if it does, a standard model with a tuned decision threshold is often enough.
- Downsample the majority class so each batch contains positives, then upweight the kept majority examples by the same factor so predicted probabilities still reflect the real base rate.
- Resample only the training set, keep the true class ratio in validation and test, and compare approaches with precision–recall metrics at the threshold the product will actually use.

## What to study, in order

### 1. Working with numerical data

Start here. Google Machine Learning Crash Course, Google for Developers. Course, about 80 min. Free. Last checked 2026-10-26. [Open](https://developers.google.com/machine-learning/crash-course/numerical-data)

- **Why:** Interviewers ask how you would prepare messy columns before training, and expect concrete choices for scaling, bucketing, missing values, categoricals and imbalance.
- **Read:** Read “Normalization”, “Binning”, “Scrubbing” and “Qualities of good numerical features”; continue into the Working with categorical data module for “Vocabulary and one-hot encoding” and the “High dimensionality” part of “Common issues”; then, in the Datasets, generalization, and overfitting module, read “Imbalanced datasets” and “Dividing the original dataset”.
- **Skip:** The programming exercises, “Polynomial transforms”, “Feature crosses” and its exercises, and the label-quality parts of “Common issues”.

### 2. 12. Common pitfalls and recommended practices

Free alternative. scikit-learn User Guide, scikit-learn developers. Guide, about 20 min. Free. Last checked 2026-10-26. [Open](https://scikit-learn.org/stable/common_pitfalls.html)

- **Why:** Leakage is the classic way a model looks great offline and fails in production, and interviewers expect you to spot it in a described pipeline.
- **Read:** Read “12.1. Inconsistent preprocessing” and all of “12.2. Data leakage”, including “12.2.1. How to avoid data leakage” and “12.2.2. Data leakage during pre-processing”.
- **Skip:** “12.3. Controlling randomness”, unless you are asked about reproducible splits.

### 3. Feature Engineering and Selection: A Practical Approach for Predictive Models

Go deeper. feat.engineering, Max Kuhn and Kjell Johnson. Guide, about 1 h 40 min. Free. Last checked 2026-10-26. [Open](https://feat.engineering/)

- **Why:** It treats splitting, encoding and missing data as modelling decisions with trade-offs, the depth a senior interviewer probes after the textbook answer.
- **Read:** In chapter 3 read “3.3 Data Splitting”, “3.4.1 V-Fold Cross-Validation and Its Variants”, “3.4.4 Rolling Origin Forecasting” and “3.4.7 What Should be Included Inside of Resampling?”; in chapter 5 read “5.1 Creating Dummy Variables for Unordered Categories” to “5.4 Supervised Encoding Methods”; in chapter 8 read “8.1 Understanding the Nature and Severity of Missing Information” to “8.5 Imputation Methods”.
- **Skip:** The R “Computing” sections, the long case-study figures, chapter 5’s ordered and text encodings, and chapters 9–12 on profile data and feature selection.

## Companies that test this area most

- [Google DeepMind](https://saadho.arushk.tech/companies/google-deepmind)
- [Flipkart](https://saadho.arushk.tech/companies/flipkart)
- [Sarvam AI](https://saadho.arushk.tech/companies/sarvam-ai)
- [Krutrim](https://saadho.arushk.tech/companies/krutrim)
- [Info Edge (Naukri)](https://saadho.arushk.tech/companies/info-edge)
- [Amazon](https://saadho.arushk.tech/companies/amazon)

## Related

- [All topics](https://saadho.arushk.tech/library)
- [Build a plan that includes this](https://saadho.arushk.tech/start)
