Can sklearn random forest directly handle categorical features?

后端 未结 3 566
予麋鹿
予麋鹿 2020-12-04 11:35

Say I have a categorical feature, color, which takes the values

[\'red\', \'blue\', \'green\', \'orange\'],

and I want to use it to predict something in a ra

3条回答
  •  盖世英雄少女心
    2020-12-04 12:04

    You have to make the categorical variable into a series of dummy variables. Yes I know its annoying and seems unnecessary but that is how sklearn works. if you are using pandas. use pd.get_dummies, it works really well.

提交回复
热议问题