Classification of a number of naive Bayes

How do you classify a row of individual cells in MATLAB?

At the moment, I can classify individual colors as follows:

training = [1;0;-1;-2;4;0;1]; % this is the sample data.
target_class = ['posi';'zero';'negi';'negi';'posi';'zero';'posi'];
% target_class are the different target classes for the training data; here 'positive' and 'negetive' are the two classes for the given training data

% Training and Testing the classifier (between positive and negative)
test = 10*randn(25, 1); % this is for testing. I am generating random numbers.
class  = classify(test,training, target_class, 'diaglinear')  % This command classifies the test data depening on the given training data using a Naive Bayes classifier

Unlike the above, I want to classify:

        A   B   C
Row A | 1 | 1 | 1 = a house

Row B | 1 | 2 | 1 = a garden

Here is a sample code from MATLAB:

nb = NaiveBayes.fit(training, class)
nb = NaiveBayes.fit(..., 'param1', val1, 'param2', val2, ...)

I do not understand what is param1, val1etc. Can anyone help?

+5
source share
1 answer

Here is an example adapted from the docs:

%# load data, and shuffle instances order
load fisheriris
ord = randperm(size(meas,1));
meas = meas(ord,:);
species = species(ord);

%# lets split into training/testing
training = meas(1:100,:);         %# 100 rows, each 4 features
testing = meas(101:150,:);        %# 50 rows
train_class = species(1:100);     %# three possible classes
test_class = species(101:150);

%# train model
nb = NaiveBayes.fit(training, train_class);

%# prediction
y = nb.predict(testing);

%# confusion matrix
confusionmat(test_class,y)

the conclusion in this case was 2 times classified instances:

ans =
    15     0     1
     0    20     0
     1     0    13

Now you can configure all kinds of parameters for the classifier (parameter / value that you mentioned), just send the documentation to describe each ..

, . , .

+3

All Articles