What is frequency (count) encoding?
easyAnswer
- Replace each category with its count (or frequency) in the training set.
- Works well for tree models: high-frequency categories often behave differently from rare ones, and this captures that in one column instead of one-hot's thousands.
- Doesn't leak the target so it's safer than target encoding for high-cardinality categoricals.
- Downside: two categories with the same count get the same encoding, so it's information-losing — often combined with other encodings.
Check yourself — multiple choice
- Replace category with the target mean
- Replace with the category's count/frequency in training — safe, tree-friendly, but collision-prone
- One-hot encode every category
- Drop rare categories only
Frequency encoding: category → count. Safe, useful for trees, but two categories with the same count collide.
#encoding#features
Practise Supervised Learning
215 interview questions in this topic.
Related questions
- How do decision trees handle categorical features?
- Ordinal vs nominal encoding — how do you choose?
- What is target encoding and when is it useful?
- How do you prevent leakage in target encoding?
- What is feature hashing (the 'hashing trick') and when is it useful?
- What is Weight of Evidence (WoE) encoding?