Naive Bayes Classification for categorical values

Hi, I have a dataset containing numerical and categorical data. I like to use Naive Bayes Classifier in the following link but it only confers with numerical values.
Does anyone have an idea about how to extend that code to categorical data as well?

 Accepted Answer

Convert the categoricals to doubles.
c = categorical({'red';'blue';'red'})
double(c)

4 Comments

That's a good idea but I am using tables. When I do that, I loose my column names
converted=double(tNonNumeric{:,:});
coverted_arr=array2table(converted);
merged_w_converted= [tNumeric coverted_arr];
What can I do about that?
And also I'm getting Subscripted assignment dimension mismatch. error in following part of the code from the link above
for i=1:num_of_classes
for j=1: height(xi)
xi=x((y==yu(i)),:);
mu(i,:)=mean(xi{j,:},1); %it was originally mean(xi,1)
sigma(i,:)=std(xi{j,:},1);
end
end
The table is nice for storing but not for these computations. Reconvert to a table after with the same names from the original table (T.properties.variableNames).
Hi i just realized that converting categorical to double makes things complicated. For example it gives different values to the ones that are actually same. I see values 127 ,96 all sort of different ones in a column where all of them were actually 'yes'. So what should I do about it?

Sign in to comment.

More Answers (0)

Asked:

Ege
on 25 Nov 2014

Commented:

Ege
on 4 Jan 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!