Encode an unseen category explicitly

Return to the home row after each number or separator. · 179 words

Categorical encoding turns text labels into numbers that a model can read. Suppose a library wants to classify books as fiction, history, or biography. With one-hot encoding, each category gets its own column: fiction is [1, 0, 0], history is [0, 1, 0], and biography is [0, 0, 1]. This avoids pretending that the distance between category numbers has meaning. The encoding rule must also state what happens when a category was not seen during training.

A concrete unseen case is a new book labeled poetry. Instead of silently giving it the code for fiction, the training scheme reserves an OTHER or UNSEEN category and maps every unseen label to that fixed value. If one-hot vectors are used, UNSEEN can have its own coordinate, such as [0, 0, 0, 1]. The same mapping must be saved and reused when the model makes predictions. During evaluation, include some genuinely unseen labels and report how often the model routes them to UNSEEN. An OTHER bucket is not a substitute for understanding the new category, but it prevents an accidental, misleading substitution.

Check your recall

How should a model encode a category that does not appear in its training data?

Check your answer

Reserve an explicit OTHER or UNSEEN category and map the new label to that fixed encoding. Use the same rule during prediction and evaluation, rather than assigning it an arbitrary existing category.

Sources and credits

Original KeyTouch lesson. Background reading · Google · Machine Learning Crash Course.