필터 지우기
필터 지우기

How to train a Naive Bayes classifier?

조회 수: 1 (최근 30일)
Lara Lirnow
Lara Lirnow 2017년 4월 4일
편집: Don Mathis 2017년 4월 11일
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))

Community Treasure Hunt

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

Start Hunting!

Translated by