Encoding an Unordered Feature with One-Hot Values

One-hot features give each supported category a separate position without assigning an ordinary numeric order to category names.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace three categories
  2. Handle an unseen value
  3. Encode categories without implying ordinal distance
  4. Specify new and absent labels

Trace three categories

Colors red, blue, and gray can be represented by 100, 010, and 001 under a fixed vocabulary. Treating them as integers one, two, three would create artificial distances. See one-hot state encoding.

Handle an unseen value

Choose a separate unknown label, a rejection rule, or an encoding with specified behavior. Keep the mapping stable for later inputs. Exhaustive conditions help cover supported and unsupported cases.[1]

Encode categories without implying ordinal distance

Suppose modes are air, rail and road. In that fixed order, rail can use vector \((0,1,0)\). Encoding them as one, two and three would make rail numerically between the others, whether or not that relation exists. See one-hot state patterns.

Air → 1,0,0
Rail → 0,1,0
Road → 0,0,1
A fixed vocabulary ties each column to its meaning

Specify new and absent labels

An unknown mode at serving time requires a documented outcome, such as a reserved unknown value. Test an unseen label and a reordered input schema. Do not infer vocabulary from the evaluation set.

References

  1. Gareth James et al., An Introduction to Statistical Learning ↩