# One-hot encoding

> Canonical: https://skillalmanac.com/glossary/one-hot-encoding | Last verified: 2026-11-25 | Index status: index-eligible

One-hot encoding represents each categorical feature with indicator columns, assigning 1 to its observed category and 0 to the other represented categories.

Also called: one-of-K encoding.

## In plain language

One-hot encoding turns a categorical value into a binary indicator vector defined by a fixed vocabulary and order. With color vocabulary [red, blue, green], red becomes [1, 0, 0] and blue becomes [0, 1, 0]. Each categorical feature has its own vector; a row with several features can therefore contain several ones after those vectors are combined.

## Technical definition

Canonical full one-hot encoding creates one indicator per represented category of each feature, with exactly one 1 in that feature’s vector for a known single-valued category. Implementations may instead drop a category, group infrequent categories or define special unknown-category behavior. An unseen value may raise an error, map to an infrequent bucket or produce all zeros, depending on explicit settings. These variants are not equivalent, and not every model requires one-hot inputs.

## How it shows up when you use agents

One-hot encoding is useful when an agent workflow passes categorical records to a model or estimator that expects numeric features. The vocabulary and order must be explicit. Suppose `color` uses [red, blue] and `size` uses [small, large]. For a red, large item, the color feature’s indicator vector is [1, 0], while the size feature’s indicator vector is [0, 1]. Concatenating them gives [1, 0, 0, 1]. There are two ones because there are two categorical features; “one hot” applies separately to each known, single-valued feature.

Before fixing the vocabulary, inspect spelling and case. `Blue`, `blue` and `blue ` can accidentally become separate indicators. The EDA skill can surface such variants and numeric-looking codes, but it does not perform the encoding.

## Common confusions

Assigning red = 1 and blue = 2 is integer coding, not one-hot encoding. Those numbers can introduce an unintended order or distance. One-hot indicators avoid that particular implication, although they do not guarantee that the resulting features suit every model.

Full one-hot encoding and dropped-category variants differ. With full encoding, [red, blue] produces two columns. A configured drop policy might retain only the blue column, making red [0] and blue [1]. That exception should be named rather than described as canonical full one-hot encoding.

Unknown categories also require an explicit policy. If green was absent from the vocabulary [red, blue], an implementation might reject it. With a setting such as ignoring unknowns, it might produce [0, 0], which is not a standard known-category one-hot vector and can be confused with a dropped reference category. Another configuration may group it into an infrequent-category column. Record the vocabulary, column order, drop policy, grouping policy and unknown handling with the transformed data. Not all model families require or benefit from one-hot encoding.

## Worked examples in this catalogue

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Use the data-analysis EDA skill before encoding to inspect category spellings, case variants, distinct values, leading-zero codes and frequent values in a CSV.

Why it exercises the concept: Those checks can expose accidental duplicate categories and numeric-looking codes before a vocabulary is fixed. The skill does not choose an encoding policy, implement one-hot encoding, train a model or determine how unknown and infrequent categories should be handled.

## Related terms

- [Categorical data](https://skillalmanac.com/glossary/categorical-data.md)
- [Feature engineering](https://skillalmanac.com/glossary/feature-engineering.md)
- [Feature extraction](https://skillalmanac.com/glossary/feature-extraction.md)
- [scikit-learn](https://skillalmanac.com/glossary/scikit-learn.md)

## Sources

- [Machine Learning Glossary: one-hot encoding](https://developers.google.com/machine-learning/glossary#one-hot-encoding), Google for Developers (accessed 2026-11-25)
- [OneHotEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html), scikit-learn (accessed 2026-11-25)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
