EasyDeepLearn

How do decision trees handle categorical features?

medium

Answer

  • Native support depends on the library.
  • Classic CART considers only binary splits: partition category set A vs the rest, or the exhaustive best partition (2(k1)1  possibilities,  expensive  for  high  cardinality)(2(k - 1) - 1\;\mathrm{possibilities}, \;\mathrm{expensive}\;\mathrm{for}\;\mathrm{high}\;\mathrm{cardinality}). scikit-learn does *not* support categoricals natively — you must one-hot encode.
  • LightGBM has native categorical splits via Fisher's optimal partitioning.
  • CatBoost uses ordered target encoding.
  • XGBoost added native categorical support in 1.5+.
  • Native handling is usually stronger and faster than one-hot for high-cardinality categoricals.
Check yourself — multiple choice
  • All tree libraries handle categoricals identically
  • Native support varies: LightGBM/CatBoost/newer XGBoost handle them directly; scikit-learn needs one-hot
  • Trees can only use numeric features
  • One-hot encoding is always the best approach for trees

LightGBM/CatBoost/XGBoost ≥1.5 have native cat support; scikit-learn requires encoding.

#decision-trees#trees#features#encoding

Practise Supervised Learning

215 interview questions in this topic.

Related questions