Trouble with NaiveBayes object in Statistics toolbox (R2010a)
2 views (last 30 days)
Show older comments
Hello,
I am having trouble using the NaiveBayes class and associated functions in my R2010a. Specifically, I am unable to run the NaiveBayes.fit demo on the demo dataset. When I say:
load fisheriris >> O1 = NaiveBayes.fit(meas,species);
I get ??? Error using ==> vertcat CAT arguments dimensions are not consistent.
Error in ==> NaiveBayes.fit>gaussianFit at 540 obj.Params(i,obj.GaussianFS) = mat2cell([mu;sigma],2,...
Error in ==> NaiveBayes.fit at 498 obj = gaussianFit(obj, training, gindex);
I tried t o look for an overload function for gaussianFit but did not find any.
I am however, able to run it with a 'mvmn' density model rather than a Gaussian density (default). Despite this, when I run
[post,cpre] = O1.posterior(meas);
I get all NaNs in the result. I checked that the values in O1.params are not NaNs.
What could be wrong? Any help is appreciated.
0 Comments
Accepted Answer
Tom Lane
on 25 Aug 2011
This is odd. it appears to be having trouble concatenating mu and sigma, which came out of these two earlier lines:
mu = nanmean(training(groupI,obj.GaussianFS));
sigma = nanstd(training(groupI,obj.GaussianFS));
Would you check to see if you have any of these on your path outside of their usual MATLAB locations: nanmean, nanstd, sum, nansum, nanvar?
More Answers (1)
Tom Lane
on 26 Aug 2011
I would not expect this to be a problem unless your path was set up in an unusual way. If I type "which nansum" I see the stats version. If I type "which -all nansum" I see the fints version after the stats version. If I type "type nansum" I see the contents of the stats version. What do those three commands do for you?
See Also
Categories
Find more on Naive Bayes 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!