Categorical Encoding

Last Updated: July 29, 2026 | By Mihail Sebastian | AI Dictionary

Converts non-numeric categories like color or job title into numbers a machine learning model can compute with, via one-hot, ordinal, or target encoding.

What is Categorical Encoding?

Categorical encoding converts non-numeric categories (values like “Red,” “Berlin,” or “PhD”) into numbers a machine learning model can compute with. The choice of encoding shapes what the model learns: a bad one invents order that isn’t there or leaks the answer into the features.

Types of Categorical Encoding

  1. One-hot encoding gives each category its own binary column. The default for nominal categories, where no order exists.
  2. Ordinal (label) encoding assigns each category an integer. Appropriate only when the categories have a real order, such as education levels from high school to PhD.
  3. Target encoding replaces each category with the average target value observed for it. Compact for high-cardinality variables, but computing it from training labels risks data leakage unless done carefully.
  4. Hashing trick maps categories into a fixed-length vector with a hash function, trading a few collisions for bounded size.

Choosing an Encoding

Two questions settle most cases. Do the categories have a real order? If yes, ordinal encoding preserves it; if no, one-hot avoids inventing one.

And how many distinct values are there? A handful suits one-hot; thousands (user IDs, ZIP codes) call for target encoding or hashing, because one-hot would explode the column count.

Example of Categorical Encoding

A lender builds a loan-approval model with two categorical fields: education level and marital status.

Education has a natural order, so it becomes ordinal: high school 1, bachelor’s 2, master’s 3, PhD 4. Marital status does not, so it becomes one-hot: separate binary columns for single, married, and divorced.

The model now uses both fields numerically without being misled. Had marital status been encoded 1, 2, 3 instead, the model would treat “divorced” as three times “single,” an ordering no one intended.

Related AI terms: One-Hot Encoding · Hashing Trick · Feature Engineering · Data Leakage · Word Embedding

Did you like the Categorical Encoding gist?

Learn about 250+ need-to-know artificial intelligence terms in the AI Dictionary.

Mihail Sebastian — Writes about AI governance, regulation, and the technology behind them. Placeholder bio — replace with a real credential line. About

Read the Governor's Letter

Stay ahead with Governor's Letter, the newsletter delivering expert insights, AI updates, and curated knowledge directly to your inbox.

By subscribing to the Governor's Letter, you consent to receive emails from AI Guv.
We respect your privacy - read our Privacy Policy to learn how we protect your information.

Browse All AI Terms A–Z

Every term in the dictionary, in alphabetical order. Jump to a letter or scroll the full list.

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z