How to train a Naive Bayes classifier?

2 Ansichten (letzte 30 Tage)
Lara Lirnow
Lara Lirnow am 4 Apr. 2017
Bearbeitet: Don Mathis am 11 Apr. 2017
I have a dataset which looks like this:
I need to use a Naive Bayes classifier to classify these rows (observations) by Category- 'unvoiced' and 'voiced'. I was looking some examples on fisheriris dataset but it didn't work. I would appreciate if someone could give me some hint or with what to start. I separated dataset into dataTesting (for testing) and dataTraining (for training the classifier).

Antworten (1)

Don Mathis
Don Mathis am 11 Apr. 2017
Bearbeitet: Don Mathis am 11 Apr. 2017
How about this?
% Make a synthetic dataset
STE = rand(84,1)*20;
ZCR = randi(900,84,1);
Category = [repmat({'unvoiced'},42,1); repmat({'voiced'},42,1)];
STE(1:42) = 15 + STE(1:42); % Make class 1 different so there's something to learn.
D = dataset(STE, ZCR, Category);
% Note: You should convert your dataset to 'Table' because dataset is deprecated:
T = dataset2table(D);
% You could have created a table directly like this: T = table(STE, ZCR, Category);
% Fit naive bayes model
model = fitcnb(T, 'Category')
% Compute cross-validated error. Chance misclassification rate would be 0.5
MisclassificationRate = kfoldLoss(crossval(model, 'KFold', 10))

Community Treasure Hunt

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

Start Hunting!

Translated by