title: Naive Bayes: the within-class variance in each feature of TRAINING must be positive
body: <p>When trying to fit Naive Bayes:</p>
  
  <pre><code>    training_data = sample; % 
      target_class = K8;
   # train model
   nb = NaiveBayes.fit(training_data, target_class);
  
   # prediction
   y = nb.predict(cluster3);
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>??? Error using ==&gt; NaiveBayes.fit&gt;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 ==&gt; NaiveBayes.fit at 498
              obj = gaussianFit(obj, training, gindex);
  </code></pre>
  
  <p>Can anyone shed light on this and how to solve it? Note that I have read a similar post <a href="http://www.mathworks.co.uk/matlabcentral/answers/40289" rel="nofollow noreferrer">here</a> but I am not sure what to do? It seems as if its trying to fit based on columns rather than rows, the class variance should be based on the probability of each row belonging to a specific class. If I delete those columns then it works but obviously this isnt what I want to do.</p>