# How would you deal with categorical data in a naive Bayesian classifier?

I've built a little naive Bayesian classifier that works with Boolean and real values. Boolean distributions are dealt with via Bernoulli distributions, while real valued data are dealt with kernel mixture estimators. I'm currently in the process of adding count data in.

How would one deal with categorical data though, e.g. Monday, Tuesday, Wednesday, or Toyota, Honda, Ford?

My initial thoughts are to assign a number to each category, treat it as a normal real value and round to the nearest integer category on prediction. That seems very wrong to me though.

• Not sure about the correct answer, but your initial thought is definitely incorrect (as you suggest), as that implies that there is an ordering to the categories. Dec 17 '12 at 20:51
• I'm not sure I follow what you mean "treat it as a normal real value and round to the nearest integer category on prediction", but it sounds like an incorrect approach. Categorical valued data is treated similar to boolean data. It is a discrete variable and should be treated as discrete, not real value. Just assign integers $1,...,K$ as labels to your $K$ categories, then use the counts to estimate parameters of your categorical distribution just as you used the counts to estimate the Bernoulli's. Dec 17 '12 at 21:21
• Correct, it is the incorrect approach. I wasn't sure what the correct technique was. Also, oddly enough the platform I'm using, Mathematica, doesn't seem to have a categorical/discrete distribution available to it. Jarad, thanks for the pointer I'll get working on this.
– user17880
Dec 17 '12 at 22:36