Categorical Encoding Cheat Sheet
Every encoding makes an assumption about the structure of a variable — here is when to use which one.
TL;DR: The best encoding is not the most sophisticated one — it is the one whose assumptions match your variable's actual structure and your model's learning mechanism.
The Problem
After years of working with tabular models, one lesson has stayed consistent: every categorical encoding makes an assumption about the structure of a variable. Choose an encoding that does not match the variable, and you hide useful signal or create leakage that looks like signal. The question is not "which encoding is most advanced?" — it is "what does this category actually mean, and what model am I using?"
The Approach
A practical starting point for encoding decisions:
Few unordered levels — one-hot encoding is usually the clean baseline. A real ranking exists — ordinal encoding can preserve that order. Many levels with stable target signal — target encoding can help, but only with smoothing and out-of-fold training. Binary classification with scorecard-style interpretability needs — WoE remains useful. Ordered factors in a linear model — contrast coding, such as Helmert or polynomial contrasts, can make specific comparisons explicit. Small or noisy groups — use stronger shrinkage rather than trusting each group's raw rate.
The model matters too. A tree-based model may handle ordinal integers very differently from a linear model. And a target encoder that looks excellent in a random validation split can fail badly once leakage is removed.
Outcome
The point is not to use every encoding method — it is to make your assumption explicit. Are categories simply different? Is there a meaningful order? Does target behaviour carry stable information? Is the signal strong enough to survive a new dataset? Ten minutes spent answering those questions per variable can save days of debugging a model that memorizes instead of generalizes.
Key Takeaway
Design insight: The best encoding is not the most sophisticated one — it is the one whose assumptions match your variable's actual structure and your model's learning mechanism.
Related
isnull() Is a Feature →Encoding Is a Modeling Decision →Necessary Conditions vs Drivers →Don't Ask Your Model to Learn What a Formula Already Knows →Adversarial Validation →SHAP Waterfall Local Explanation →LightGBM vs XGBoost in 2026 →Financial Inclusion →Sendy Logistics →Focal Loss for Imbalanced Classification →
FAQ
What is the key takeaway from "Categorical Encoding Cheat Sheet"?
The best encoding is not the most sophisticated one — it is the one whose assumptions match your variable's actual structure and your model's learning mechanism.
Who wrote this and what is it about?
This was written by Mahmoud Trigui, Senior Data Scientist. Practical guide to categorical encoding methods for tabular ML: one-hot, ordinal, target, WoE, and contrast coding — when to use each and common pitfalls.