0
$\begingroup$

In a binary classification, how can I use sklearn.naive_bayes python module to predict the class of inputs with 5 categorical variables (not binary)?

$\endgroup$
4
$\begingroup$

Hot encode the categorical variables and use Bernoulli naive Bayes. Hot encoding is usually the trick one uses in representing categorical variables.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks @Emre for your quick answer. Yes I ended up by using sklearn.preprocessing.MultiLabelBinarizer to Hot encode the categorical variables. What do you think ? $\endgroup$ – innovIsmail Jan 20 '16 at 11:16
  • $\begingroup$ Sounds good, but the documentation says All classifiers in scikit-learn do multiclass classification out-of-the-box, so you should be able to let sklearn do the encoding. If it does not work for you let us know. $\endgroup$ – Emre Jan 20 '16 at 17:01
  • $\begingroup$ Yes I ended up by using sklearn.preprocessing.MultiLabelBinarizer before using sklearn.naive_bayes.BernoulliNB and gave pretty nice results (not satisfied though) :) $\endgroup$ – innovIsmail Jan 20 '16 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.