Assuming that there is no bug anywhere in your code (or NaiveBayes code from mathworks), and again assuming that your training_data is in the form of NxD where there are N observations and D features, then columns 2, 5, and 6 are completely zero for at least a single class. This can happen if you have relatively small training data and high number of classes, in which a single class may be represented by a few observations. Since NaiveBayes by default treats all features as part of a normal distribution, it cannot work with a column that has zero variance for all features related to a single class. In other words, there is no way for NaiveBayes to find the parameters of the probability distribution by fitting a normal distribution to the features of that specific class (note: the default for distribution is normal
).
Take a look at the nature of your features. If they seem to not follow a normal distribution within each class, then normal
is not the option you want to use. Maybe your data is closer to a multinomial model mn
:
nb = NaiveBayes.fit(training_data, target_class, 'Distribution', 'mn');