[R] RWeka and naiveBayes

Kuhn, Max Max.Kuhn at pfizer.com
Thu Nov 1 15:07:35 CET 2007


Sancar,

> I'm trying to use RWeka to use a NaiveBayes Classifier(the Weka
> version). However it crashes whenever there is a NA in the class
> Gender

It is difficult to tell what the problem is without the data (or a
reproducible toy example), but it seems like you are trying to remove NA
values three different times:

  First time:  data=d2[valid.set,]
  Second time: subset=valid.set
  Thrid time:  na.action=na.exclude

The second approach may be conflicting with the others since the 1st and
3rd methods may reduce the dimensions of the input data and valid.set
probably matches the original dimensions.

Try using

  NB(formula=Gender~age,data=d2,na.action=na.exclude)

> Anybody have an idea how to fix this. or a very detailed explanation
> of how to use "naiveBayes" function from e1071 package? I tried using
> this function , too. However I can't figure out what the returning
> error means?

In e1071, the default works fine:

  tmp <- iris
  tmp$Species[1] <- NA
  tmp$Sepal.Width[10] <- NA
  naiveBayes(Species~., data = tmp) # no error

See ?naiveBayes for the reason.

Max



More information about the R-help mailing list