One-Hot Encoding
Last Updated: July 29, 2026 | By Mihail Sebastian | AI Dictionary
A categorical encoding method that turns each category into its own binary column, marking membership with a 1 and every other position with a 0.
What is One-Hot Encoding?
One-hot encoding converts a categorical variable into binary columns, one per category, where exactly one column holds a 1 and the rest hold 0. It is the most widely used form of categorical encoding for categories with no natural order.
The point is to avoid inventing order where none exists. Encoding Red, Green, and Blue as 1, 2, 3 would tell the model that Blue is “three times” Red; separate binary columns make no such claim.
How One-Hot Encoding Works
Each distinct category becomes its own column. A row gets a 1 in the column matching its category and 0 everywhere else, so every row is a vector with a single “hot” position.
The cost is dimensionality. A variable with 5 categories adds 5 columns, but a ZIP-code field with 40,000 values adds 40,000 mostly-zero columns. For high-cardinality variables like that, alternatives such as target encoding or the hashing trick keep the feature count bounded.
Example of One-Hot Encoding
A dataset has a Color column with the values Red, Green, Blue, Green. One-hot encoding replaces that single column with three binary ones:
import pandas as pd
data = pd.DataFrame({'Color': ['Red', 'Green', 'Blue', 'Green']})
one_hot = pd.get_dummies(data['Color'])
Pandas orders the new columns alphabetically (Blue, Green, Red). The first row, Red, becomes (0, 0, 1); each Green row becomes (0, 1, 0); the Blue row becomes (1, 0, 0).
Every row carries exactly one 1. The model now sees three independent binary features and never assumes Green sits “between” Red and Blue.
Related AI terms: Categorical Encoding · Hashing Trick · Feature Engineering · Word Embedding
Did you like the One-Hot 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