Skip to content
Tech Interview Prep
Technical interview guide

Feature Engineering & Selection

Turning raw data into model-ready inputs, and choosing which ones actually help.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: scikit-learn stable preprocessing, composition, selection, and inspection guidance and Google ML Crash Course feature guidance accessed 2026-08-31..

Overview

Curated: · Written: · Reviewed:

Feature Engineering & Selection

In one line

Turning raw data into model-ready inputs, keeping only features whose value was knowable at the prediction moment and that improve held-out performance. Reach for it whenever model inputs come from event logs, tables or request payloads.

Key definitions

  • Point-in-time correctness: each value uses only rows with event_time and ingestion_time at or before the prediction time.
  • Target leakage: a feature that carries the outcome, or data written after it.
  • Training-serving skew: the same feature computed differently offline and online.
  • Out-of-fold encoding: target statistics computed only from folds other than the row's own.
  • Missingness indicator: a binary column recording that a value was absent, kept beside the imputed value.
  • Permutation importance: the held-out score drop when one column is shuffled. Correlated substitutes hide each other.

Formulas and complexity

Smoothed target encoding:

p^=positives+prior⋅αrows+α\hat{p} = \frac{\text{positives} + \text{prior} \cdot \alpha}{\text{rows} + \alpha}

Standardization uses training-fold statistics only:

z=x−μtrainσtrainz = \frac{x - \mu_{\text{train}}}{\sigma_{\text{train}}}

Cyclic hour encoding (sin⁡(2πh/24),cos⁡(2πh/24))(\sin(2\pi h/24), \cos(2\pi h/24)): the Euclidean distance between 23:00 and 00:00 is 2sin⁡(π/24)≈0.262\sin(\pi/24) \approx 0.26, and between 23:00 and 20:00 it is 2sin⁡(π/8)≈0.772\sin(\pi/8) \approx 0.77. Centering a sparse one-hot matrix fills every zero. For 200,000 rows by 5,000 float64 columns that is 200,000×5,000×8 bytes=8 GB200{,}000 \times 5{,}000 \times 8\text{ bytes} = 8\text{ GB}.

How it works

  1. Define the entity, prediction time, label horizon and action. Record each feature's event time, ingestion time, source, owner and serving path.
  2. For each prediction, take the row with the latest event_time among rows whose ingestion_time is at or before the prediction time.
  3. Fit every learned step (imputer, scaler, vocabulary, target encoder, selector) inside the training fold, then apply it to validation or test rows.
  4. Run the same fixtures through offline and online transform code and compare values, types, unknown categories and rounding.
Raw events with event_time and ingestion_time Point-in-time join at prediction time Fit imputer, scaler, encoder inside training fold Selection inside the CV loop Model Serving uses the same versioned transform

Worked join from the feature store table: P1 at 2024-03-06 gets 90 (event 03-04, ingested 03-04). The 200 row was ingested 03-09, so it is invisible. P2 at 2024-03-10 gets 150 (event 03-07, ingested 03-08). The 200 row has an earlier event_time, so the latest event wins.

When to use and when not to

ChoiceUse whenAvoid when
StandardizeDistance, gradient or penalty models (k-NN, SVM, regularized linear)Tree splits, where scaling changes nothing
Impute plus missing flagAbsence carries signal, e.g. lactate drawn only when infection is suspectedAbsence has no mechanism and is pure noise
One-hotLow or moderate cardinality, unordered categoriesThousands of categories; use hashing or out-of-fold target encoding
Filter selectionOne pick reused across several model families, fast enough for the budgetModel-specific interactions matter and the budget allows wrappers
Wrapper selectionSmall candidate sets with budget for repeated fitsHundreds of features under a tight refresh deadline
Feature crossDomain-motivated pairs with dense dataRare combinations, which overfit

Traps interviewers probe

  1. Fitting the imputer, scaler, encoder or selector on all rows before splitting. Fix: put them in a Pipeline and run it inside each CV fold. For time data, use TimeSeriesSplit.
  2. Imputing away a signal. Fix: a NULL refund that means no refund becomes 0.00. A NULL sensor reading that means failure stays missing, with an indicator.
  3. Dropping a rare but strong binary feature with VarianceThreshold. A column with 4 fraud rows out of 1,000 has variance 0.004 × 0.996 ≈ 0.004, below 0.01, so it is removed. Fix: select on a score that reflects the label, and check the rows that were dropped.
  4. Taking an unseen category as harmless. With drop='first' and handle_unknown='ignore', an unseen country encodes as all zeros, which equals the dropped reference. Fix: state that behavior, count unknown rates, and monitor them.
  5. Logging amounts with zeros or negatives. log(0) is -inf, and log(-12.5) is nan. Adding 1e-9 turns refunds into about -20.7 and leaves chargebacks as nan. Fix: use a sign-aware transform or a separate flag.

Interview tips

Open with: a feature is valid only if its value was knowable at the decision, and every learned step is fit inside the training fold.

Expected follow-ups:

  • Late-arriving data: use ingestion_time, not event_time, to decide availability.
  • Skew: replay the same raw requests through both paths and diff the feature values.
  • Importance versus causality: importance is predictive only. Answer a causal question with an experiment.
  • Retirement: remove consumers first, then the writer, then the store entry.

30-second outline:

  1. Name the entity and prediction time.
  2. State the point-in-time join rule.
  3. Fit all learned steps inside a pipeline per fold.
  4. Handle missingness by mechanism, with an indicator where absence carries signal.
  5. Run selection inside CV, and use grouped permutation or ablation for correlated features.
  6. Describe the offline/online parity test and the monitoring of feature distributions.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.