Hi
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
Here is the.code I have with d2 as the data frame.
The first call to NB doesn't make R crash but the second call does.
NB <-
make_Weka_classifier("weka/classifiers/bayes/NaiveBayesSimple")
d2[,64]<-d2$Gender=="M"
NB(Gender~age,d2,na.action=na.exclude) #1st call
d2$Gender[d2$Gender==""]<-NA
valid.set<-(!is.na(d2$Gender)&(!is.na(d2$age)))
NB(formula=Gender~age,data=d2[valid.set,],subset=valid.set,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?
naiveBayes(formula=Gender~age,data=d2[valid.set,],subset=valid.set,na.action=na.exclude)
I get the following error
Error in tapply(var, y, mean, na.rm = TRUE) :
arguments must have same length
Thanks
--
Sancar Adali
Johns Hopkins University
Graduate Student
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 > GenderIt 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