What Is Feature Engineering? Definition and Examples
Quick answer
Feature engineering explained: what it means, why scaling and encoding matter, a worked scikit-learn example with illustrative data, and common mistakes.
Feature engineering is the work of turning raw data into inputs a model can learn from. It includes cleaning columns, scaling numbers, encoding categories as numbers and creating new columns, such as age groups, from existing ones. Good features can help a model more than switching to a fancier algorithm.
Key takeaways
- Feature engineering converts raw columns into numeric inputs a model can use.
- Common steps are scaling numbers, one-hot encoding categories and binning continuous values.
- Scaling matters because a feature with a much larger variance can dominate the objective function.
- Fit every transform on training data only, then apply it to test data.
On this page:
- What feature engineering means
- How it works, with code
- Where it is used
- Common mistakes and confusions
- Related terms
- Frequently asked questions
| Term | What it does | Example |
|---|---|---|
| Feature engineering | Builds and shapes model inputs | Scale area, encode city |
| Data cleaning | Fixes errors and gaps in raw data | Remove duplicate rows |
| Feature selection | Chooses which features to keep | Drop a column that adds nothing |
| Model training | Learns patterns from the finished features | Fit a regression |
What does feature engineering mean?
A feature is one input column the model sees, such as flat area or city. Feature engineering is the plain-language practice of preparing those columns. This is the everyday working definition found in textbooks.
Why bother? According to the scikit-learn documentation (version 1.9.1), standardisation of datasets is a common requirement for many estimators, and they might behave badly if individual features do not look like standard normally distributed data, meaning Gaussian with zero mean and unit variance. It also warns that a feature whose variance is orders of magnitude larger than others might dominate the objective function and make the estimator unable to learn from the other features as expected.
How does feature engineering work?
You inspect each column, decide how a model should see it, and transform it. Three common moves are scaling, encoding and binning.
An illustrative before-and-after for three flats in Pune (made-up numbers):
| Column | Raw values | What the model sees |
|---|---|---|
| area_sqft | 850, 1400, 2100 | Scaled to zero mean and unit variance |
| city | Pune, Pune, Mumbai | Two 0/1 columns, one per city |
Encoding. The scikit-learn documentation says one-hot encoding transforms each categorical feature with n categories into n binary features, with one of them 1 and all others 0. It also explains why not to use plain integer codes: they would interpret the categories as being ordered, which is often not desired.
Binning. According to Google's Machine Learning Crash Course, binning (also called bucketing) is a feature engineering technique that groups different numerical subranges into bins. It describes quantile bucketing as creating boundaries so that each bucket has exactly or nearly the same number of examples. For example, age groups 18 to 25, 26 to 35, 36 to 50 and 51 and above could serve as buckets in a loan model (illustrative).
The code below applies scaling and encoding. It needs scikit-learn and NumPy. The comments show the values you should see, worked out by hand from the formulas (StandardScaler divides by the population standard deviation).
from sklearn.preprocessing import StandardScaler, OneHotEncoder
import numpy as np
area = np.array([[850], [1400], [2100]])
print(StandardScaler().fit_transform(area).round(2).ravel())
# [-1.17 -0.1 1.27]
city = np.array([["Pune"], ["Pune"], ["Mumbai"]])
print(OneHotEncoder(sparse_output=False).fit_transform(city))
# [[0. 1.]
# [0. 1.]
# [1. 0.]] columns are Mumbai, PuneWhere is feature engineering used?
It is used in almost every supervised machine learning project: house price models, loan default models, churn prediction and demand forecasting. An illustrative Indian example: a rent model for a city starts from raw listings, turns area into a scaled number, locality into one-hot columns and building age into buckets.
A practical checklist (textbook practice, not a measured result): check each column's type, scale numeric inputs for models that are sensitive to scale, one-hot encode categories, bucket skewed values if a straight line fits poorly, and fit transforms on training data only.
What are the common mistakes and confusions?
- Fitting a scaler on all the data before splitting. Information from the test set leaks into training. Fit on the training set only.
- Encoding categories as 1, 2, 3. The model may read an order that is not there.
- Confusing it with data cleaning. Cleaning fixes errors; feature engineering shapes the inputs.
- Creating features without checking they help. Compare model results with and without each new feature.
Which terms are related?
Features feed into models such as linear regression and neural networks, and are judged with tools like the confusion matrix. Poorly chosen features can also lead to overfitting. For context, see data science vs data analytics and Python for data science.
Next step
Run the snippet, then replace the numbers with a small dataset of your own. Try a model with raw columns and again with engineered ones, and compare. For wider context, read machine learning vs deep learning.
Frequently asked questions
What is feature engineering in simple words?
Feature engineering is preparing raw data so a model can learn from it. It includes scaling numbers, encoding categories as numbers, grouping values into bins and creating new columns from existing ones.
Why do we scale features?
According to scikit-learn, a feature whose variance is orders of magnitude larger than others might dominate the objective function and stop the estimator learning from the other features as expected.
What is one-hot encoding?
One-hot encoding turns a categorical feature with n possible values into n binary columns, where one is 1 and the rest are 0. It avoids implying an order between categories.
What is binning in feature engineering?
Binning, also called bucketing, groups numerical subranges into bins. Google's Machine Learning Crash Course lists it as a feature engineering technique. Quantile bucketing makes buckets with nearly equal numbers of examples.
Is feature engineering the same as data cleaning?
No. Data cleaning fixes errors, duplicates and gaps in raw data. Feature engineering shapes the cleaned data into inputs that suit a model, such as scaled or encoded columns.