Skip to content
AI360Xpert
Glossary
Definition

One-Hot Encoding

Turning a categorical column into one binary column per category, with exactly one set to 1 in every row.

colour = green over the vocabulary [amber, blue, green, teal] becomes [0, 0, 1, 0]. Four columns, one hot, and no claim that any colour is larger than another — which is exactly what makes it right for unordered categories.

It stops working on high cardinality. Fifty thousand categories means fifty thousand columns, each almost entirely zeros, so the output should stay a sparse matrix and a dense conversion is how pipelines run out of memory.

Two mechanics worth knowing. With an intercept the columns sum to 1 in every row, making the matrix rank-deficient, so unpenalised linear models want drop_first. And a category absent from training has no column, so at serving time it either raises or silently produces an all-zero row the model scores anyway.