Feature engineering

Feature engineering is the work of choosing, building and transforming the input variables a machine learning model learns from, turning raw data into features that make the patterns easier to learn.

Google's machine learning glossary describes feature engineering as two steps: deciding which features might be useful for training a model, and converting raw data from the dataset into efficient versions of those features. Its example is temperature: having decided it matters, you might try grouping it into ranges to see which version helps the model learn most.

Typical moves include deriving new values (the day of the week from a timestamp, or the number of days since a customer's last order), converting categories into numbers with one-hot encoding, rescaling numbers so that features on very different scales are comparable, grouping values into ranges, combining two features into one (a feature cross) and filling in missing values. Dimensionality reduction and feature selection, which cut the number of features, are often counted as part of the job.

For most of machine learning's history this was where projects were won or lost. In a 2012 review in Communications of the ACM, Pedro Domingos wrote that the features used are easily the most important factor in success, and that constructing them from raw data is typically where most of a project's effort goes. He noted that newcomers are often surprised how little time is spent on the learning itself.

Deep learning changed the balance. Networks trained on raw pixels, sound or text learn their own features, so image and language systems need far less hand-crafting than they once did, though they still need careful data preparation. Automated feature engineering tools have also appeared: one method, Deep Feature Synthesis, beat 615 of 906 human teams in a competition, and open-source libraries such as featuretools generate features from relational and time-series data.

Two rules apply whoever does the work. A feature must be computable at the moment of prediction, using only information available then; a feature built with knowledge of the outcome causes leakage and a falsely good test score. And the same calculation must be used in training and in production, or the model will see different inputs from the ones it learned on.

Common questions

What is feature engineering with an example?

It is turning raw data into inputs a model can learn from more easily. For example, a model predicting shop sales might do better with features such as day of the week and whether it is a public holiday, derived from a raw date, than with the date itself.

Is feature engineering still needed with deep learning?

Less than it was for images, audio and text, where deep networks learn their own features from raw data. Those systems still need careful preprocessing and cleaning, and choosing their architecture and settings takes its own trial and error.

What is the difference between feature engineering and feature selection?

Feature engineering covers the whole job of creating and transforming features. Feature selection is one part of it: choosing which of the available features to keep, usually to reduce noise, cost or overfitting.

Can feature engineering be automated?

Partly. Tools can generate large numbers of candidate features from relational and time-series data and keep the most useful ones. In one competition, the Deep Feature Synthesis method beat 615 of 906 human teams. Domain knowledge is still needed to judge which features make sense.

Finding more

Search for "feature engineering", "feature selection" or "automated feature engineering". Course material from machine learning providers, library documentation and well-cited review articles explain the techniques. Treat claims that a tool removes the need for domain knowledge with care.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.