kiinalist
2012-May-05 06:21 UTC
[R] what is Non-numeric argument to mathematical function in prediction ?
Hi, I tried to use naivebayes in package 'e1071'. when I use following parameter, only one predictor, there is an error. > m <- naiveBayes(iris[,1], iris[,5]) > table(predict(m, iris[,1]), iris[,5]) 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. > m <- naiveBayes(iris[,1:2], iris[,5]) > table(predict(m, iris[,1:2]), iris[,5]) setosa versicolor virginica setosa 49 0 0 versicolor 1 37 19 virginica 0 13 31 Do you know what is the problem? Br, Luffy [[alternative HTML version deleted]]
Petr Savicky
2012-May-05 09:53 UTC
[R] what is Non-numeric argument to mathematical function in prediction ?
On Sat, May 05, 2012 at 09:21:10AM +0300, kiinalist wrote:> Hi, > > I tried to use naivebayes in package 'e1071'. > when I use following parameter, only one predictor, there is an error. > > > m <- naiveBayes(iris[,1], iris[,5]) > > table(predict(m, iris[,1]), iris[,5]) > 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. > > > m <- naiveBayes(iris[,1:2], iris[,5]) > > table(predict(m, iris[,1:2]), iris[,5]) > > setosa versicolor virginica > setosa 49 0 0 > versicolor 1 37 19 > virginica 0 13 31Hi. A untested suggestion is to try m <- naiveBayes(iris[,1, drop=FALSE], iris[,5]) The difference is that iris[,1] is not a dataframe, while both iris[,1:2] and iris[,1, drop=FALSE] are. Hope this helps. Petr Savicky.