# What is the way to represent factor variables in scikit-learn while using Random Forests?

I am solving a classification problem using Random Forests. For that I have decided to use Python library scikit-learn. But I am new to both Random Forest algorithm and this tool. My data contains many factor variables. I googled for that and found out that it's not right to give numerical values to factor variables like we do in linear regression, as it will treat it as continuous variable and give wrong result. But I could not find anything about how to deal with factor variables in scikit-learn. Please tell me the options to use or point me to some document where I can get it.

• Converting factors to continuous value is equally bad for RF as for linear regression -- it may decrease your accuracy but it is unlikely that this will completely spoil the model.
– user88
Jun 18 '13 at 13:51

It seems that you're comparing scikit-learn's Random Forest with randomForest package in R, where this package deals with categorical variables automatically.