Blogpost · November 25, 2025

Feature Engineering: Making Data Understandable for Machines

Why models fail without the right features and how to guide them

by Perivitta 30 mins read Intermediate
Share
Back to all posts

Feature Engineering: Making Data Understandable for Machines

Introduction

There is a rule of thumb in machine learning that surprises most beginners: the features you give a model usually matter more than which model you choose. A well-engineered simple model routinely outperforms a poorly-fed complex one. In machine learning competitions, experienced practitioners typically spend eighty percent of their time on features and twenty percent on models, not the other way around.

This counterintuitive reality has a straightforward explanation. A machine learning model is a pattern-finding machine. Feed it numbers, and it finds mathematical relationships between those numbers and the target you are predicting. But a model can only find patterns in the information you give it, in the form you give it. Feature engineering is the discipline of transforming raw data into a form that makes the patterns genuinely visible.


The Problem: Why Raw Data Is Not Enough

Consider a concrete example. You are building a model to predict whether a restaurant will be busy on a given evening. One of your columns is a timestamp, the date and time of each historical observation. That raw timestamp, as a large integer representing seconds since some reference date, is nearly useless to most models. A linear regression has no concept of what the number 1736800000 means in terms of human behavior.

But extract three derived features from that timestamp, the hour of the day, the day of the week, and whether the date falls on a public holiday, and suddenly the model can learn that restaurants are busier on Saturday evenings, that Friday lunch is different from Monday lunch, and that holidays create unusual demand patterns. The underlying information was always there in the raw data. Feature engineering is the process of unlocking it.

Without thoughtful features, models learn irrelevant patterns, like the exact numerical value of a timestamp, instead of meaningful ones like "it is Saturday evening." They produce unstable predictions that depend on accidents of the training data, and they fail when exposed to real-world data with slightly different characteristics. Feature engineering is the bridge between raw information and meaningful learning.

Supervised machine learning workflow from training data to predictions
Figure: The supervised ML workflow, training data flows through a learning algorithm to produce a model, which then makes predictions on new inputs. Feature engineering shapes the quality of inputs at every stage. Poor features constrain everything downstream; good features amplify even simple algorithms. Source: EpochFail / Wikimedia Commons (CC BY-SA 4.0)

Core Concepts and Terminology

Feature engineering is the process of transforming raw data into features, the input variables that a machine learning model actually uses to learn from. A feature is any measurable property of what you are trying to model, represented numerically so that an algorithm can operate on it.

There is an important distinction between raw data and features. Raw data is what you collected: transaction timestamps, customer addresses, product descriptions, sensor readings. Features are derived from raw data in ways that make the information useful for prediction. The date "2026-02-03" is raw data. The features "day of week is Tuesday," "month is February," "is weekend is false," and "days since last purchase is 14" are derived from it, each providing the model with a handle on patterns that are actually meaningful.

Concept Definition Example
Raw feature Data in its original collected form Timestamp: 1736800000
Engineered feature Derived from raw data to expose meaningful patterns Hour of day: 19, Day of week: Friday
Feature transformation Mathematical operation applied to a raw feature Log transform of income distribution
Feature interaction Combining multiple features into one Age multiplied by income level
Encoding Converting non-numeric data into numbers One-hot encoding of car type categories

How It Works: Core Feature Engineering Techniques

Transforming Raw Numbers

Numeric features in real-world data often span wildly different scales. A house price prediction model might include square footage (ranging from 300 to 5,000) alongside number of bedrooms (ranging from 1 to 5). Without scaling, a one-unit change in square footage appears to the model as equivalent to a one-unit change in bedrooms, even though the scales are completely different and the raw numbers carry no comparable meaning.

Scaling addresses this by re-expressing features on a common scale. Standardization centers each feature at zero and scales it to unit variance, making features comparable regardless of their original units. This is essential for algorithms that measure distance between points, like k-nearest neighbors, or that use gradient-based optimization, like logistic regression and neural networks, which are sensitive to the magnitude of inputs.

Beyond scaling, other numeric transformations solve specific problems. A log transform is applied to right-skewed distributions, income, house prices, website traffic, where a small number of very large values distort the distribution. Taking the logarithm compresses the tail and makes linear relationships more visible. Binning converts continuous variables like age into discrete categories (18–25, 26–40, 41–60, 60+), which can help tree-based models and adds interpretability when domain knowledge suggests that thresholds matter more than exact values. Clipping caps extreme outliers at a sensible maximum, preventing a handful of unusual observations from distorting the model's behavior.

Creating New Features from Existing Ones

Derived features combine existing columns into something more informative than any single column alone. This is where domain knowledge pays off most directly, because the person who understands the domain intuitively knows which combinations carry meaning.

Average spend per order, computed as total spending divided by number of orders, captures spending intensity far better than either column alone. Body mass index, computed as weight divided by the square of height, is a medical domain combination that is more predictive of health outcomes than either weight or height separately. Days since last login, derived from today's date minus the last login date, converts an absolute timestamp into a relative measure of engagement recency that generalizes across users and time periods.

The key question to ask when creating derived features is whether the combination encodes something a domain expert would find meaningful and interpretable. If yes, it is almost always worth testing. The best features come from deep understanding of what the data actually represents, not from automated combination of columns.

Encoding Categorical Variables

Machine learning models operate on numbers. Text categories, "SUV," "Sedan," "Truck", need to be converted to numerical representations before a model can use them. The choice of encoding method matters significantly, because different methods make different assumptions about the structure of the categories.

One-hot encoding creates one binary column per category value. A car type column with values SUV, Sedan, and Sports becomes three columns, one for each type, where each observation has a one in exactly one column and zero in the rest. This is appropriate for nominal categories with no natural ordering, but it can produce a large number of columns for features with many distinct values.

Ordinal encoding maps categories to integers in a meaningful order. Education level (high school as 1, bachelor's as 2, master's as 3, doctoral as 4) has a natural ordering that ordinal encoding preserves. Critically, ordinal encoding should only be used when the order genuinely matters, encoding colors as red equals 1, blue equals 2, green equals 3 implies that blue is "more" than red, which is meaningless and misleading.

Target encoding replaces each category with the average value of the target variable for observations in that category. For a high-cardinality feature like zip code, this is often more effective than one-hot encoding because it compresses the information into a single column while preserving predictive signal. However, it requires careful handling to prevent data leakage, the encoding statistics must be computed only from training data, never from the full dataset including test observations.

Handling Missing Data

Real-world data almost always contains missing values, and most models cannot handle them directly. The approach you choose matters because each strategy makes a different assumption about why the data is missing, and getting that assumption wrong introduces bias.

Mean or median imputation is the simplest approach: replace missing values with the average or median of the observed values. It is fast and stable but assumes that the missing data is random, that there is no systematic reason why some observations lack the value. When that assumption holds, it is reasonable. When it does not, the imputation introduces systematic distortions.

Sentinel value imputation replaces missing values with a distinctive value that signals "missing", such as negative one for a feature that is always non-negative in real data. This approach lets the model learn that missingness itself is informative, useful when data is missing for a reason, such as a customer who never answered a particular survey question.

The most reliable approach combines imputation with a missingness indicator: creating a separate binary column that records whether each value was originally missing, alongside the imputed value. This lets the model use both the imputed value and the fact of missingness as separate signals, without discarding either.

The golden rule for all imputation: fit your imputer only on training data. If you compute the mean of the entire dataset, including test observations, and use it to impute training values, you have given the model indirect access to information about the test set. This is a form of data leakage, covered in detail below.

Removing Noise and Irrelevant Features

More features is not always better. Every feature you include gives the model a new opportunity to find spurious patterns and overfit to them. Features that add noise without adding signal actively harm model performance, particularly for complex models with many parameters.

Correlation analysis can identify features that are highly correlated with each other but not with the target, these are redundant and one can be removed. Feature importance scores from tree-based models provide a rough measure of how much each feature contributed to predictions, making low-importance features easy to identify. But the most reliable filter is domain knowledge: before any model, ask whether each feature could plausibly be causally related to the target. An account number is almost certainly irrelevant to predicting customer churn. Remove it before modeling rather than hoping the model will learn to ignore it.


Practical Example: Building Features for a Churn Prediction Model

A telecommunications company wants to predict which customers are likely to cancel their service in the next thirty days. The raw data includes account creation date, last payment date, monthly bill amount, number of support calls in the past year, and contract type.

A naive approach feeds these columns directly into a model. But the raw values carry limited signal. The account creation date as an integer tells the model nothing useful. Last payment date as a raw timestamp is similarly opaque.

A thoughtful feature engineering approach transforms the raw data into meaningful signals. Account creation date becomes account age in days, a relative measure that captures whether someone is a long-tenured customer. Last payment date becomes days since last payment, a recency measure that the model can easily learn thresholds for. Monthly bill amount gets a log transform to compress the skewed distribution of high-usage customers. A new derived feature captures support calls per month by dividing the annual count by months active, normalizing for different tenure lengths. Contract type, a categorical variable with values "month-to-month," "one-year," and "two-year," is one-hot encoded into three binary columns.

Each of these transformations makes a meaningful pattern more visible and more learnable. The feature engineering did not invent new information, it reorganized existing information into a form the model can actually use.


Advantages of Thorough Feature Engineering

  • Raises the performance ceiling: Even the best algorithm cannot extract information that is not present in the features. Good features set the upper bound on what any model trained on them can achieve.
  • Enables simpler, more interpretable models: When features are well-designed, simpler models often perform as well as complex ones, and they are much easier to understand, audit, and explain to stakeholders.
  • Improves generalization: Features grounded in domain knowledge tend to be stable across data collected at different times or from different sources, leading to models that hold up in production.
  • Reduces data requirements: A well-engineered feature encodes knowledge that the model would otherwise need to discover from data alone, often requiring far more observations than are available.
  • Facilitates debugging: Models trained on meaningful, named features are much easier to diagnose when something goes wrong, you can examine feature distributions and identify which inputs are driving unexpected predictions.

Limitations and Trade-offs

  • Feature engineering requires domain expertise: The best features come from understanding what the data actually means, something that cannot be automated without significant domain knowledge. In new domains, building good features takes time and iteration.
  • Risk of encoding bias: If the training data reflects historical biases, features derived from it will encode those biases into the model. Engineered features that seem intuitive can inadvertently encode protected characteristics or historical inequities.
  • Increased pipeline complexity: Every transformation applied during training must also be applied at inference time, in the same order, with the same parameters. More feature engineering means more to maintain, version, and monitor in production.
  • Deep learning partially reduces but does not eliminate the need: Neural networks can learn representations automatically given sufficient data, but they still benefit from thoughtful input representations and they require much more data to discover the same patterns that a well-designed feature encodes explicitly.

The Silent Model Killer: Data Leakage

Data leakage is one of the most dangerous and hardest-to-detect problems in machine learning. It occurs when information from outside the proper training context contaminates your features, producing a model that appears exceptional in validation but collapses in production. It is the most common cause of the "works in notebook, fails in production" pattern, and it is treacherous precisely because it improves your validation metrics, hiding behind an impressive number.

Target Leakage

Target leakage occurs when a feature contains information about the target that would not be available at the time you actually need to make a prediction. The model learns to exploit a signal it could never have in the real world.

The clearest example: predicting whether a customer will file an insurance claim, using a feature called "has open claim." At the time you need to make the prediction, before any claim is filed, that feature does not exist yet. The model trains on information that is only available after the outcome has already occurred. Its validation performance looks perfect; its production performance is worthless, because the feature it learned to rely on will never be present at prediction time.

The test for target leakage is simple to state but requires vigilance to apply: at the moment you need to make this prediction in the real world, would this feature's value actually be known? If not, remove it from the training data entirely.

Temporal Leakage

Temporal leakage occurs in time-series contexts when future data is used to construct features for past observations. Rolling statistics are the most common source of this problem.

Suppose you compute a thirty-day rolling average of daily revenue across your full dataset before splitting into training and test sets. For observations near the train-test boundary, the rolling window looks forward into what will become the test set, dates the model should never have seen during training. The model appears capable of predicting future revenue, but it is actually peeking at it through the leaking rolling window.

The fix requires discipline: always split time-series data chronologically before computing any time-window features. All feature computation must strictly respect the temporal boundary. Features for training observations must use only data that was available before the training cutoff date.

Preprocessing Leakage

Even standard preprocessing steps like scaling and imputation can introduce leakage when fitted on the full dataset before splitting. A scaler fitted on all observations uses the test set's statistical properties to transform training data, giving the model indirect access to information it should not have. This is subtle but real, and it inflates validation performance in ways that are difficult to detect.

The reliable prevention strategy is to use a preprocessing pipeline that is fitted only on training data and then applied, without refitting, to validation and test data. When performing cross-validation, each fold must refit the preprocessing steps independently so that no fold's validation data influences the preprocessing applied to training data within that fold.


Feature Engineering Across Different Model Types

Not all models respond equally to feature engineering choices. Understanding which models need what kinds of features helps you prioritize where to invest your time.

Model Type Feature Sensitivity What Matters Most
Linear and Logistic Regression Very high Scaling is essential. Nonlinear relationships must be encoded manually through polynomial features or log transforms. Collinear features destabilize coefficient estimates.
Decision Trees and Random Forests Moderate Scale-invariant, trees split on thresholds, not distances. Can work with raw features, but noisy columns increase overfitting risk. Missingness indicators help.
K-Nearest Neighbors Extremely high Scaling is critical, features on different scales dominate distance calculations. Irrelevant features are especially damaging in high dimensions.
Gradient Boosting (XGBoost, LightGBM) Low to moderate Can learn complex feature interactions automatically. Scale-invariant. Still benefits meaningfully from well-designed derived features and removal of genuinely irrelevant columns.
Neural Networks Moderate Can learn representations automatically with sufficient data. Better input representations still lead to faster training, better generalization, and lower data requirements.

Common Mistakes Practitioners Make

  • Computing statistics on the full dataset before splitting: This is one of the most common sources of data leakage. Always split first, then compute any statistics (means, medians, encodings, rolling averages) on training data only.
  • Adding too many features without filtering: Every additional feature is another opportunity for the model to overfit. Features that add noise outweigh their potential benefits. Apply domain knowledge filtering before adding any new column.
  • Using ordinal encoding for nominal categories: Encoding "red," "blue," and "green" as 1, 2, and 3 implies a numerical ordering that does not exist. Use one-hot encoding for unordered categories.
  • Skipping imputation strategy analysis: Defaulting to mean imputation without asking why data is missing often introduces systematic bias. Understanding the mechanism of missingness is prerequisite to choosing the right imputation strategy.
  • Not reproducing feature engineering at inference time: A feature transformation applied during training must be reproduced exactly at inference time. Missing or incorrectly reproduced transformations are a major source of model failures in production.

Best Practices

  • Start with domain knowledge, not automation: The most valuable features reflect understanding of what the data actually means. Talk to domain experts before reaching for automated feature generation tools.
  • Engineer features before tuning models: Before increasing model complexity, ask whether the current features give the model the right information in the right form. Fix features first; tune models second.
  • Use preprocessing pipelines: Encapsulate all feature transformations in a reproducible pipeline that applies the same steps consistently during training, validation, and inference. This prevents leakage and ensures reproducibility.
  • Document every transformation: For each engineered feature, record what transformation was applied, why it was chosen, and what statistics (means, scales, encoding mappings) it depends on. This documentation is essential for maintaining models in production.
  • Validate features independently: Before training a full model, examine each engineered feature individually: Is it distributed as expected? Does it have the expected relationship with the target? Catching problems early saves significant time later.

Frequently Asked Questions

Do I still need feature engineering if I use deep learning?

Yes, though the emphasis shifts. Deep neural networks can learn useful representations from raw inputs given sufficient data, but they still benefit from thoughtful preprocessing and domain-informed input structure. For tabular data, the most common format in business applications, feature engineering often matters as much with deep learning as with traditional models. The data requirements to replace feature engineering with learned representations are usually very high.

How do I know which features to keep and which to remove?

A combination of domain reasoning and empirical testing. Remove features that have no plausible causal connection to the target. Then use feature importance scores or ablation studies, removing one feature at a time and measuring the impact on validation performance, to identify which engineered features are actually contributing. Be conservative: when in doubt, keep features that domain experts believe are relevant.

What is the difference between feature selection and feature engineering?

Feature engineering creates new features from existing data, transforming, combining, or encoding raw information into more useful representations. Feature selection chooses which existing features to include in the model. Both disciplines improve model performance, but they work at different stages of the pipeline. Feature engineering typically comes first, expanding the set of candidate features; feature selection then narrows that set to the most relevant ones.

How do I detect data leakage if I don't know what to look for?

The clearest warning sign is validation performance that seems too good, especially if the model performs dramatically worse on new production data than it did in validation. Other signals include features with near-perfect correlation with the target, features whose values would logically only be known after the event you are predicting, and rolling window features computed before the train-test split. When performance drops sharply in production, data leakage is one of the first things to investigate.

Should I one-hot encode every categorical variable?

Not necessarily. One-hot encoding is appropriate for low-cardinality nominal categories. For high-cardinality features (cities, zip codes, product IDs with hundreds or thousands of values), one-hot encoding creates an unwieldy number of columns and often performs poorly. Target encoding or frequency encoding tends to work better in those cases. For ordinal categories, ordinal encoding preserves meaningful order information that one-hot encoding discards.


References


Key Takeaways

  • Features set the ceiling on model performance, even the best algorithm cannot extract information that is not present in the features you provide. Invest in features before investing in model complexity.
  • The core techniques, scaling, log transforms, categorical encoding, derived features, and missingness indicators, address specific structural problems in raw data that models cannot solve on their own.
  • Different model types have different feature sensitivities, linear models and distance-based models need careful scaling and encoding; tree-based models are more robust but still benefit from well-designed features.
  • Data leakage is the silent model killer, it produces models that appear excellent in validation and fail in production. Always split before computing statistics, and always ask whether each feature's value would truly be known at prediction time.
  • Feature engineering requires domain knowledge, the best features come from understanding what the data actually means, not from automated search or generic transformations.
  • Every transformation must be reproduced at inference time, use preprocessing pipelines to ensure consistency and prevent the subtle production failures that arise from mismatched transformations between training and deployment.

Related Articles

AI in Finance: ML for Trading, Risk, and Fraud Detection
AI in Finance: ML for Trading, Risk, and Fraud Detection
Machine learning powers fraud detection, credit scoring, and algorithmic trading. Learn how...
Read More →
Decision Trees: A Complete Guide with Hand-Worked Examples
Decision Trees: A Complete Guide with Hand-Worked Examples
Decision trees split data by finding the best question at each node....
Read More →
Found this useful?