Encode (in Feature Engineering)#
Converting categorical or text data into numeric form for models.
Important
✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
What it is#
Encoding converts categorical (non-numeric) data into a numerical form, because most ML algorithms operate only on numbers. The trick is to add the numbers without inventing meaning that isn’t there.
The methods#
One-hot encoding turns a category into several binary columns (exactly one 1) — right for nominal categories with low cardinality, since it implies no order. Ordinal / label encoding assigns integers, valid only when categories are genuinely ordered. For high-cardinality features, frequency, target, or learned embedding encodings avoid the column explosion of one-hot.
Getting it wrong#
Label-encoding a nominal variable (red = 1, blue = 2, green = 3) falsely tells the model green > blue — a fake ordering that distance- and gradient-based models will believe. Match the encoding to whether the category is ordered, and to its cardinality.
Theme: Data Preparation & Features · All terminology
Hint
Mind map — connected ideas
Normalize (in Feature Engineering) · Sensitivity in Feature Engineering · Embedding · Feature Values · Outlier · Neural Networks
Hint
More in Data Preparation & Features
Advanced Sorting in Spreadsheets · Normalize (in Feature Engineering) · Sensitivity in Feature Engineering
See also
Source article Adapted (context, re-expressed) in our own words from: Encode (in Feature Engineering) (insightful-data-lab.com).