Naive Bayes: variance within a class in each TRAINING function must be positive

When trying to install naive bayes:

training_data = sample; % target_class = K8; # train model nb = NaiveBayes.fit(training_data, target_class); # prediction y = nb.predict(cluster3); 

I get an error message:

 ??? Error using ==> NaiveBayes.fit>gaussianFit at 535 The within-class variance in each feature of TRAINING must be positive. The within-class variance in feature 2 5 6 in class normal. are not positive. Error in ==> NaiveBayes.fit at 498 obj = gaussianFit(obj, training, gindex); 

Can anyone shed some light on this and how to solve it? Please note that I read a similar post here , but I'm not sure what to do? It seems to be trying to fit on the basis of columns rather than rows, the variance of a class should be based on the probability of each row belonging to a particular class. If I delete these columns, then it will work, but obviously this is not what I want to do.

+7
source share
1 answer

Assuming your code is missing an error code (or NaiveBayes code from mathworks), and again it is assumed that your training_data data is in NxD form, where there are N observations and D functions, then columns 2, 5 and 6 are completely zero, by at least for one class. This can happen if you have relatively small training data and a large number of classes in which one class can be represented by several observations. Since NaiveBayes, by default, considers all functions as part of a regular distribution, it cannot work with a column that has zero variance for all functions associated with one class. In other words, NaiveBayes cannot find the probability distribution parameters by fitting the normal distribution to the functions of this particular class (note: the default value for the distribution is normal ).

Take a look at the nature of your possibilities. If they do not seem to correspond to the normal distribution within each class, then normal is not the option you want to use. Perhaps your data is closer to the multi-dimensional mn model:

 nb = NaiveBayes.fit(training_data, target_class, 'Distribution', 'mn'); 
+12
source

All Articles