Feature engineering

On this page 7

Feature engineering is the process of transforming raw data into input variables, called features, that represent the underlying problem in a form a model can learn from. In data processing, it follows data cleaning, deduplication and the handling of missing data, and it decides what information a predictive model can actually see.

Good features often matter more than the choice of algorithm. A model predicting delivery delays learns little from a raw timestamp, but much more from derived features such as hour of day, day of week, distance to depot and the number of parcels already queued for the same route.

How feature engineering works

Feature engineering works by encoding domain knowledge and data structure into numeric or categorical columns aligned to a single unit of prediction, such as one customer, one transaction or one day. The process usually iterates: create candidate features, evaluate their effect on validation performance, keep the useful ones and discard noise.

  1. Define the prediction unit and timestamp, the moment at which features must be known.
  2. Clean and align sources, resolving duplicates, missing values and inconsistent units.
  3. Transform, encode and aggregate raw fields into candidate features.
  4. Evaluate candidates with validation scores and feature importance.
  5. Package the final logic in a reproducible pipeline used identically for training and scoring.

The last step is critical. When training features are computed in a notebook and production features in separate code, small differences create training-serving skew, a frequent reason why models perform worse after deployment than in testing.

Organizations with many models often centralize this logic in a feature store, which keeps feature definitions, computes them on a schedule or in streaming mode and serves the same values to training jobs and live applications. A feature store also provides point-in-time correct joins, so historical training rows receive feature values exactly as they existed at that moment. Automated feature generation tools can enumerate aggregations and transforms at scale, but they produce many redundant candidates and still need domain review.

Common feature engineering techniques

Most techniques fall into a few families, each addressing a specific property of the raw data.

TechniqueWhat it doesTypical example
Scaling and normalizationPuts numeric values on comparable rangesStandardize income to zero mean and unit variance
Mathematical transformsReduces skew or captures nonlinearityLog of purchase amount, squared distance
BinningGroups continuous values into intervalsAge bands such as 18-24 and 25-34
Categorical encodingTurns labels into numbersOne-hot, target or frequency encoding
Date and time featuresExtracts cycles and durationsWeekday, month, days since last order
AggregationsSummarizes history per entityOrders in the last 30 days per customer
Interactions and ratiosCombines variablesDebt-to-income ratio, price per square meter
Text and embeddingsConverts unstructured content to vectorsWord counts, sentence embeddings
Main families of feature engineering techniques

Cyclical encoding deserves special mention: hour 23 and hour 0 are adjacent, so representing time with sine and cosine components lets a model see that closeness, which a plain integer cannot express.

Feature engineering is distinct from but dependent on the cleaning steps that precede it. Cleaning makes data correct, while feature engineering makes it informative for a specific prediction task.

StepGoalOutput
Data cleaningFix errors and inconsistenciesCorrect, standardized records
DeduplicationRemove repeated entities or eventsOne record per real-world item
ImputationFill missing values plausiblyComplete columns, often with flags
Feature engineeringRepresent the problem for a modelInformative input variables
Feature selectionKeep the most useful featuresSmaller, more robust feature set
Feature engineering and neighboring processing steps

The boundaries overlap. Adding a missing-value indicator next to an imputed column is both imputation and feature engineering, because the fact that a value was missing is often predictive in itself.

Choosing features for different models

The right amount of feature engineering depends on the model family. Some algorithms need carefully prepared inputs, while others discover structure themselves when given enough data.

Model familyNeeds scalingHandles interactions itselfFeature engineering effort
Linear and logistic regressionYesNoHigh: transforms and interactions matter
Distance-based modelsYesPartlyHigh: scale and relevance matter
Tree ensemblesNoYesMedium: aggregations and encodings matter
Deep neural networksYesYesLower for raw text, images and audio
Feature needs by model family

Even with deep learning, tabular business data benefits from hand-crafted aggregations such as recency, frequency and monetary value, because those summaries capture behavior across many raw events that a model cannot easily reconstruct.

Pitfalls in feature engineering

The most serious pitfall is target leakage, where a feature uses information unavailable at prediction time. Aggregations computed over the whole dataset, including future rows, and target encoding without out-of-fold estimation are common sources.

PitfallConsequencePrevention
Target leakageExcellent tests, poor production resultsCompute features strictly as of the prediction time
Fitting transforms on all dataOptimistic validation scoresFit scalers and encoders on training folds only
High-cardinality one-hot encodingHuge sparse matrices, overfittingUse target, hashing or frequency encoding
Training-serving skewSilent accuracy loss after launchShare one pipeline or a feature store
Feature explosionSlow training, unstable modelsSelect features and regularize
Feature engineering pitfalls

Features can also encode sensitive attributes indirectly, for example postal code standing in for ethnicity or income. Reviewing features for fairness and stability belongs in the process, not after deployment.

Stripped to the essentials

A computer model only learns from the columns it is given. Feature engineering is the work of turning messy raw records into clear, useful clues, much as a doctor turns a long patient history into a few key facts such as age, blood pressure and recent symptoms.

The raw data may contain everything, but not in a helpful form. Well-chosen clues make the model smarter without changing the model at all.

Where it is applied

A bank’s fraud team trains a model on card transactions. The raw data holds only the amount, merchant, timestamp, card number and location. The team engineers features as of each transaction: number of transactions on the card in the last hour, ratio of the amount to the card’s 90-day median, distance from the previous transaction divided by elapsed time, whether the merchant category is new for the cardholder and the hour of day encoded cyclically.

All aggregations use only earlier transactions, and the same feature code runs in training and in the real-time scoring service. Compared with a model trained on raw fields alone, the engineered model flags fraudulent transactions with noticeably higher precision at the same alert volume, so analysts review fewer false alarms while catching more real fraud.