# Should one binarize qualitative variables before applying a random forest?

On which of theses two kinds of sample would a Random Forest (and more precisely sklearn RandomForest algorithm) give the best results ? (Y and other_features are continuous numerical variables, and the "cat_variable" modalities are not unbalanced).

 Y | other_features | cat_variable
...| ...            | A
...| ...            | B
...| ...            | B
...| ...            | B
...| ...            | C
...| ...            | A

Y | other_features | is_A | is_B | is_C |
...| ...            | 1    | 0    | 0    |
...| ...            | 0    | 1    | 0    |
...| ...            | 0    | 1    | 0    |
...| ...            | 0    | 1    | 0    |
...| ...            | 0    | 0    | 1    |
...| ...            | 1    | 0    | 0    |


My question intend to be quite general : I'm looking for the best practice, and I want to know if binarizing categorical variables has an interest. If this is still unclear, I would be pleased if you explain me why.

• NO, you should not – kjetil b halvorsen Sep 12 '18 at 20:36
• RF is perfectly capable of handling categorical variables so there is no need for this. Also, you do not want to to create needless additional variables. – user2974951 Sep 13 '18 at 7:51