What Is Feature Engineering? Better Data for Better Models
Feature engineering turns raw data into inputs a model can learn from. See the common techniques, a runnable Python example, and the mistakes that cause data leakage.
Short answer: feature engineering is the process of turning raw data into useful inputs, called features, that a machine learning model can learn from. A date becomes "days since signup", a city becomes a set of 0/1 columns, and two columns become a ratio. Good features often improve a model more than switching to a fancier algorithm.
What is a feature?
In supervised learning, a model learns to predict a target (for example, "will this customer return?") from features: the measurable facts you give it, such as age, number of orders or time since the last visit. Models only understand numbers, and they only learn from patterns that are visible in the features. Feature engineering is the work of making those patterns easy to see.
Why does feature engineering matter?
Raw data is rarely model-ready. It has text, dates, missing values and mixed units.
Good features carry the signal. A model cannot easily find "recent customers" from a raw timestamp, but it can from "days since last order".
Simple models become strong. With informative features, even a basic model can do well.
What are the common feature engineering techniques?
Technique | What it does | Example |
|---|---|---|
Encoding categories | Turns labels into numbers | City becomes one 0/1 column per city (one-hot) |
Scaling | Puts numbers on a similar range | Age and income both scaled to a common range |
Handling missing values | Fills or flags gaps | Fill with the median and add an "is_missing" column |
Date and time features | Extracts useful parts | Day of week, month, days since an event |
Ratios and combinations | Combines columns | Total spent divided by number of orders |
Binning | Groups numbers into ranges | Age into 18–25, 26–40 and so on |
Text features | Turns text into numbers | Word counts, or an embedding |
What does feature engineering look like in code?
This small script uses only the standard library. It builds three kinds of features for a made-up shop: dates turned into day counts, a ratio, and one-hot city columns.
from datetime import date
orders = [
{"signup": date(2025, 1, 10), "last_order": date(2025, 3, 1), "orders": 4, "spent": 80, "city": "Northvale"},
{"signup": date(2025, 2, 1), "last_order": date(2025, 2, 20), "orders": 0, "spent": 0, "city": "Eastbrook"},
]
cities = ["Northvale", "Eastbrook"]
def make_features(row, today=date(2025, 4, 1)):
avg = row["spent"] / row["orders"] if row["orders"] else 0.0 # ratio feature
features = {
"days_since_signup": (today - row["signup"]).days, # date -> number
"days_since_last_order": (today - row["last_order"]).days,
"avg_order_value": avg,
}
for c in cities: # one-hot encoding
features[f"city_{c}"] = 1 if row["city"] == c else 0
return features
for row in orders:
print(make_features(row))Running it prints:
{'days_since_signup': 81, 'days_since_last_order': 31, 'avg_order_value': 20.0, 'city_Northvale': 1, 'city_Eastbrook': 0}
{'days_since_signup': 59, 'days_since_last_order': 40, 'avg_order_value': 0.0, 'city_Northvale': 0, 'city_Eastbrook': 1}Notice the guard against dividing by zero for a customer with no orders. Handling edge cases like this is part of the job. In practice you would do the same with pandas on whole columns; see how it fits in preparing ML-ready data with SQL and pandas.
Does deep learning make feature engineering unnecessary?
Partly. A neural network can learn useful representations from images, audio and text, so you hand-craft fewer features there. For tables of business data, such as customers, sales or sensors, careful feature engineering is still a core skill.
Common mistakes
Data leakage. Using information that will not exist at prediction time, such as a column recorded after the outcome. The model looks excellent in testing and fails in real use.
Fitting on all the data. Compute things like the median or scaling range from the training set only, then apply them to the test set.
Too many features. More columns can add noise. Keep those you can explain and test.
Ignoring the domain. The best feature ideas often come from asking people who know the problem.
Key Takeaway
Feature engineering turns raw data into inputs a model can learn from. Encode categories, handle gaps, extract dates and build ratios, but avoid leakage by using only what you would know at prediction time.
Ready to start? You will build the numeric intuition (averages, spread, correlation) that helps you design and check features. Begin with the free course Maths and Statistics for AI: The Essentials.
Related articles
More in Machine Learning
How Does Machine Learning Detect Fraud?
Machine learning fraud detection scores every transaction using learned fraud patterns and anomaly detection. See why 99% accuracy can catch nothing, a worked precision and recall example, and runnable code.
6 min readDec 2, 2026What Is Cross-Validation? k-Fold Explained Simply
Cross-validation tests a model on several splits of the data and averages the scores. See k-fold on a tiny worked example and run it in scikit-learn.
5 min readDec 1, 2026What Is Data Labeling and Why Does AI Need It?
Data labeling adds the right answers to raw data so models can learn. See the main label types, how to measure labeler agreement, and how AI-assisted labeling works.
5 min readNov 30, 2026Gradient Descent Explained Simply
How models learn by measuring error and stepping downhill, with a runnable Python example showing learning rate, steps and local minima.
5 min readNov 23, 2026What Is Computer Vision? How AI “Sees” Images
Computer vision lets AI work with images and video. See how a picture becomes numbers, how models learn to recognise things, the main tasks, and where it goes wrong.
5 min readNov 22, 2026What Is NLP (Natural Language Processing)?
NLP is how computers read and produce human language. See how it works, the main tasks, a small Python example, and how NLP relates to LLMs.
4 min readNov 20, 2026
Comments
Sign in to join the discussion.

