Skip to content
Quantoros

How can OneHotEncoder limit a high-cardinality feature without manually listing rare values?

Classic MLLevel: IntermediateCategory cardinality control

How can OneHotEncoder limit a high-cardinality feature without manually listing rare values?

Hints
  • Group before encoding.
  • Frequency rules must be learned on training rows.

Answer

Use min_frequency or max_categories to group infrequent categories. Fit grouping only on training data and check how unseen values map at inference.

Source and licence: scikit-learn 1.7.2 — preprocessing · BSD-3-Clause · answer: Quantoros editorial

Related questions