Models need numbers, so every category has to become one without inventing an order that is not there. Two questions decide the method: do the categories have a real ordering, and how many distinct values exist?
Few values and no order means one indicator column per value. Few values with a genuine order means integer codes that preserve it. Many values means grouping the long tail into "other", hashing, target statistics, or a learned embedding.
The model family matters as well. Trees split on integer codes without reading them as magnitudes, so they tolerate compact encodings. Linear and distance-based models read 3 as three times 1.
Whatever you pick, store the mapping as a fitted object rather than ad-hoc code. Serving must produce the same columns in the same order, or the model silently scores garbage.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓