How to train a Naive Bayes classifier?

1 次查看(过去 30 天)
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).

回答(1 个)

Don Mathis
Don Mathis 2017-4-11
编辑:Don Mathis 2017-4-11
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))

类别

Help CenterFile Exchange 中查找有关 Classification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by