# Turning Categories into Numbers

Numbering categories such as dog, cat and rabbit 1, 2 and 3 invents an order and distances that aren't there, so one-hot encoding gives each category a column of its own, which OneHotEncoder learns from the training data, with handle_unknown='ignore' for a category it never saw, while OrdinalEncoder fits categories that really have an order, given in that order.

![Cheat sheet: Turning Categories into Numbers](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/e2aeb638b2df49b49cbc6992870c7585.webp)

- Category: Machine Learning
- Level: Journeyman
- Tags: ai, Categorical Feature, One-Hot Encoding, OneHotEncoder, OrdinalEncoder, python
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/ml-encoding-categories-cheat-sheet
