How to train a Naive Bayes classifier?
1 view (last 30 days)
Show older comments
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).
0 Comments
Answers (1)
Don Mathis
on 11 Apr 2017
Edited: Don Mathis
on 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))
0 Comments
See Also
Categories
Find more on Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!