one-hot encoding
/ WUN-hot en-KOH-ding /
Models do arithmetic, but many features are words: a color is "red", "green", or "blue"; a city is "Tokyo" or "Lima". If you naively code them as 1, 2, 3, the model will assume blue (3) is somehow three times red (1), or that the average of red and blue is green — pure nonsense. One-hot encoding fixes this by giving each category its own yes/no switch.
Concretely, a single category column with k possible values becomes k new columns, one per value. For any row, exactly one of those columns is 1 ("hot") and the rest are 0. So "green" becomes (red=0, green=1, blue=0). No category is treated as bigger than another; they are simply different. This keeps unordered categories — called nominal categories — honestly separate, with no fake ranking smuggled in.
Why it matters: it is the standard way to feed categorical features into models that expect numbers, from linear regression to neural networks. The cost is width: a column with thousands of categories (every product ID, say) explodes into thousands of mostly-zero columns, which is wasteful and can hurt. For such high-cardinality cases people turn to alternatives like learned embeddings. Also, one-hot is for unordered categories; if the categories have a natural order (small, medium, large), encoding them as ordered numbers can be better.
A "fruit" column with values apple, banana, cherry becomes three columns. A banana row reads (apple=0, banana=1, cherry=0); an apple row reads (apple=1, banana=0, cherry=0). The model now sees three distinct, equal-status options instead of a fake 1-2-3 ranking.
One category column becomes several 0/1 switches — equal, unranked, honest.
Watch the category count. One-hot encoding a feature with thousands of distinct values balloons your data into a sea of zeros; for high-cardinality features, learned embeddings or target encoding are usually the smarter move.