A shipping model has a “destination country” column with values like Denmark, Sweden and Norway. Models do math on numbers, so the text has to be converted. The tempting shortcut is to number them: Denmark 1, Sweden 2, Norway 3. That accidentally tells the model Norway is “three times” Denmark and that Sweden sits between them, which means nothing. One-hot encoding avoids this by creating one column per country, so each country is its own independent switch.
It is a standard step in preparing features for classic models such as linear regression and logistic regression, and it’s part of feature engineering. Two practical issues come up. The encoder needs a rule for categories that appear later but weren’t in the training data. And statistical models with an intercept usually drop one column (“dummy variables”) so the columns aren’t perfectly redundant.
The limit is size. A column with 50,000 product IDs becomes 50,000 mostly-zero columns, and the model can’t tell that two products are similar. Google’s course recommends embeddings in that case: dense vectors that place related items near each other. Language models work this way. Each token ID could in principle be written as a one-hot vector over the whole vocabulary, but the model maps it to a learned embedding instead.
Sources
- Google Machine Learning Glossary: one-hot encoding — Defines one-hot encoding as a vector with one element set to 1 and the rest 0, illustrated with five Scandinavian countries; checked October 24, 2026.
- Google Machine Learning Crash Course: Vocabulary and one-hot encoding — Explains one-hot vectors, sparse representation, and recommends embeddings or hashing when a categorical feature has a very large number of categories; checked October 24, 2026.
- scikit-learn: OneHotEncoder — Reference for the standard one-hot encoder, including options for categories unseen during training; checked October 24, 2026.