📈One-Hot Encoding
Also known as One-Hot Vector, Dummy Variables, One-Hot
Turns a word into a row of 0s with one 1. Now a model can read it.
Think of it like
It is like a row of light switches. Only one is on at a time.
Example
A house table has a city column with London, Paris or Tokyo. After one-hot encoding, a London house reads 1, 0, 0.
Why it matters
Most models only read numbers. This turns words into numbers without making up a false order.
Definition
Example code
python
import pandas as pd
pd.get_dummies(pd.Series(["London", "Tokyo"]), dtype=int)
# London Tokyo
# 0 1 0
# 1 0 1Common mistake
Key takeaways
- 1One column each. Every value gets its own column.
- 2A single 1. The rest are all 0.
- 3No false order. Blue is not bigger than red.