Q:

How can I fit categorical data types for random forest classification? 

I need to find the accuracy of a training dataset by applying Random Forest Algorithm.  But my the type of my data set are both categorical and numeric.  When I tried to fit those data, I get an error. 

'Input contains NaN, infinity or a value too large for dtype('float32')'. 

May be the problem is for object data types.  How can I fit categorical data without transforming for applying RF? 
Here's my code.   

A:

You need to convert the categorical features into numeric attributes.  A common approach is to use one-hot encoding, but that's definitely not the only option.  If you have a variable with a high number of categorical levels, you should consider combining levels or using the hashing trick.  Sklearn comes equipped with several approaches (check the "see also" section): One Hot Encoder and Hashing Trick
If you're not committed to sklearn, the h2o random forest implementation handles categorical features directly.