Skip to content

weird predict function error when I use naive bayes

2 messages · kiinalist, Uwe Ligges

#
Hi,

I tried to use naivebayes in package 'e1071'.
when I use following parameter, only one predictor, there is an error.
Error in log(sapply(attribs, function(v) { :
   Non-numeric argument to mathematical function


However, when I use two predictors, there is not error any more.
setosa versicolor virginica
   setosa         49          0         0
   versicolor      1         37        19
   virginica       0         13        31

Do you know what is the problem?

Br,
Luffy
1 day later
#
On 04.05.2012 13:54, kiinalist wrote:
Either use the more convninient formula notation:

m <- naiveBayes(Species ~ Sepal.Length, data = iris)
table(predict(m, iris), iris$Species)


or provide data.frames rather than vectors, hence:


m <- naiveBayes(iris[,1,drop=FALSE], iris[,5])
table(predict(m, iris[,1,drop=FALSE]), iris[,5])

Uwe Ligges