0
$\begingroup$

Right now I am doing some problems on application of decision tree/random forest. I am trying to fit a problem which has numbers as well as strings (such as country name) as features. Now the library, scikit-learn takes only numbers as parameters, but I want to inject the strings as well as they carry significant amount of knowledge.

How do I handle such scenario, I can convert string to numbers by some mechanism such as hashing in python. But I would like to know the best practice on how strings are handled in decision tree problems.

$\endgroup$

1 Answer 1

1
$\begingroup$

Random forests don't allow you to use strings as features. Instead, if you want to use random forests, you'll need to select new features and do some feature extraction, so that all of your features are numbers. The features might be some function of the strings, e.g., a histogram of the lengths of the strings, or a count of the number of times each possible word appears in your document (see e.g. bag of words model).

The features that make sense for your application will depend heavily upon your specific application, so we can't give a one-size-fits-all answer. The right set of features will be heavily domain-specific and application-specific, so you'll need to do some brainstorming about possible features and try out your ideas to see how well they work. That said, if you want some hints or ideas to jumpstart your brainstorming about possible features that might make sense, the NLP (natural language processing) community might be a good place to start.

$\endgroup$
0

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.