Feature Engineering

Aggregation, bucketing, normalisation, encoding, temporal and interaction features — each a transformation that must be reproduced identically at serving time.

Feature Engineering
▶ lab

A feature is a transformation from raw records to a number the model can use. It is learned from training data, and it has to be reproduced identically at serving time — which is where it usually breaks.

Q · The model is a function of its features, not of the raw data. What is a feature, who computes it, when, and what must be true for the same feature to exist in production?
Aggregation Features

Per-entity counts, sums, rates and recency over windows. They dominate tabular models, and they are the main source of train/serve skew because they depend on a clock, a source and a null policy at once.

Q · Why do a handful of windowed counts per entity outperform every other feature, and why are those same features the ones that break between training and serving?
Bucketing & Normalisation

Bucket edges, means and standard deviations are fitted on the training fold and shipped with the model. Refit them anywhere else and the model receives inputs from a transformation it never learned.

Q · Scaling and bucketing look like cleaning. Why are they part of the model, and what goes wrong when serving recomputes them?
Categorical Encoding

One-hot, ordinal and embedding encodings turn categories into numbers. Each has a vocabulary that was fitted on training data, an unseen-category policy, and a serving path that must apply both identically.

Q · A model consumes numbers. How does a category become one, what fitted state does that create, and what happens when production sends a category training never saw?
Target Encoding
▶ lab

Replace a category with the mean label for that category. Powerful on high-cardinality features, and a leak unless the rate for each row is computed without that row, out of fold, with a smoothed prior.

Q · Encoding a category as its label rate is the most effective trick for high-cardinality features. Why does the obvious version leak, and what does the out-of-fold version cost?
Temporal Features

Windows, lags, recency, calendar features and "as of" timestamps. Every one is anchored to a clock, and the rule is that the anchor is the prediction time and no window ends after it.

Q · Time is the axis along which features leak, skew and go stale. How do you build features from it that mean the same thing in training and serving?
Missing Data

Why a value is missing is information. Imputation is fitted on the training fold and shipped, the missingness indicator is often the better feature, and the null policy must be identical at serving.

Q · A null is not a value. What does its absence mean, how should the model see it, and what has to match between training and serving for the answer to hold?