0
$\begingroup$

I am currently training a random forest. After transforming a categorical feature into dichotomous columns, should I drop the first level?

For example, I have three unique values in a featured named sex:

  1. m for male
  2. f for female
  3. na for not available

Thus, I encoded sex into three columns:

sex  sex_m  sex_f  sex_na
  m      1      0       0
  f      0      1       0
 na      0      0       1

I dropped sex (obviously), but should I also drop one of the three encoded columns?

Dropping the base level is necessary when running a regression to avoid multicollinearity, but this is not a problem when running a random forest. So what is the most common approach?

For reference, each tree is being trained with a randomly selected set of 8 out of 63 features.

$\endgroup$
3

1 Answer 1

1
$\begingroup$

Technically, both will work.

However, creating dummies is rarely a good idea in random forests as it weights down the chance of other variables to be picked for splitting.

Integer coding often does the job pretty well. The more levels, the more it helps to use a meaningful order. Some implementations - e.g. ranger in R - do smart ordering, internally. Avoiding dummy coding also greatly helps to interprete the models by the usual suspects (variable importance, partial dependence plots).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.