The interview question

How would you prepare mixed numerical and categorical data for a reliable baseline?

Design transformations around prediction time, missingness, and consistent serving behavior.

01. Start with a feature contract

For each feature, write its meaning, key, units, event timestamp, availability timestamp, and default behavior. A seven-day purchase count must specify whether the current event is included and how late-arriving events are handled. A feature that cannot be reproduced at prediction time is not a usable training signal.

Begin with a small, interpretable set. For a return-visit model, recent session count, time since last visit, and account age may form a reasonable hypothetical baseline. Do not add a future cancellation flag simply because it improves validation.

02. Treat missingness as information with a cause

A missing income field could mean the user declined, a source failed, or the field did not exist in an older schema. These mechanisms need not have the same relationship to the outcome. Preserve useful missing indicators and monitor their rates.

For training values 10, 20, and 90, median imputation inserts 20. Mean imputation inserts 40. Neither creates an observed measurement. Fit the chosen statistic only on training data and keep it fixed for inference. If a feature becomes entirely unavailable in production, an imputer should not silently make a broken pipeline look healthy.

03. Match encoding to the model

One-hot encoding expresses categories without an invented order. Ordinal codes can imply distance or ordering to some models, so assigning red=1 and blue=2 is not automatically meaningful. Define behavior for unseen categories and control very high cardinality.

Target encoding uses outcome information and therefore requires especially careful out-of-fold construction. A category seen once can otherwise reveal its own label. Scaling helps distance-based and regularized models, while many tree models are less sensitive to monotonic numerical rescaling. Evaluate choices with a pipeline that prevents validation leakage.

04. Test consistency rather than feature count

Use a recorded input event to compare offline and online feature values. Check timezone boundaries, null conventions, stale caches, clipping, and categorical dictionaries. Track whether a default is a legitimate value or a fallback caused by an outage.

Follow-up: a feature is predictive but expensive to fetch. Compare the quality improvement with added latency, availability dependencies, and operational cost. You might materialize it in advance, use a cheaper proxy, or keep it only in a second-stage model. The strongest answer connects feature value to the full serving contract.

Practice the follow-up

Self-review

Design a contract for “purchases in the last hour,” including late events and the current purchase.

Connect this to data leakage.

Sources & further reading

scikit-learn: preprocessing. The interview scenario, calculations, and proposed design choices are illustrative.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.