Naive Bayes - within-class variance must be positive.

조회 수: 6 (최근 30일)
Nirmal
Nirmal 2012년 6월 4일
I am trying to use Naive Bayes for some classification task, I am not sure what it is complaining about.
??? 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 5 6 12 13 15 16 17 in class 1 are not positive.
Error in ==> NaiveBayes.fit at 498
obj = gaussianFit(obj, training, gindex);
Thank you for reading
  댓글 수: 1
the cyclist
the cyclist 2012년 6월 4일
Are you able to post a small bit of your data and code that exhibit the error?

댓글을 달려면 로그인하십시오.

채택된 답변

Tom Lane
Tom Lane 2012년 6월 5일
Suppose you have data X and classes C. Can you look at
var(X(C==1,:)
If you see that columns 5, 6, 12, etc. have zero variance, that is the problem. The fit is based on fitting a normal distribution separately for each class and feature. If any class has 0 variance for a feature, that normal fit is degenerate.
What you want to do about this depends on you. It is possible to change the fit to a kernel density estimate and specify the width. Or you could try a decision tree or knn classifier.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by