I get this error:
Warning: TRAINING can only contain
non-negative integers when
'Distribution' is set to 'mn'. Rows of
TRAINING with invalid values will be
removed.
> In NaiveBayes.fit at 317
??? Error using ==>
??? Error using ==>
NaiveBayes.fit>mnfit at 647
At least one valid observation in each
class is required.
Error in ==> NaiveBayes.fit at 496
obj = mnfit(obj,training,
gindex);
This is what I have:
training_data = Testdata;
target_class = TestDataLabels;
%# train model
nb = NaiveBayes.fit(training_data, target_class, 'Distribution', 'mn');
%# prediction
class1 = nb.predict(UnseenTestdata);
%# performance
cmat1 = confusionmat(UnseenTestDataLabels, class1);
acc1 = 100*sum(diag(cmat1))./sum(cmat1(:));
fprintf('Classifier1:\naccuracy = %.2f%%\n', acc1);
fprintf('Confusion Matrix:\n'), disp(cmat1)
The dataset is 4940201×42 if anyone is wondering.
You’ve got two problems.
First, for multinomial distributions, MATLAB wants your data to have non-negative integer values. And second, it seems like for at least some of your classes, you don’t have any valid observations. This might be because of NAN’s, INF’s, or just non-positive values in the rows of Testdata.
Actually, as the error says – “invalid rows will be removed”… so I bet invalid rows were removed…