-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of joris meys
Sent: Thursday, February 26, 2009 1:36 PM
To: r-help at r-project.org
Subject: Re: [R] Bug in predict function for naiveBayes?
Dear all,
I've sent a mail last week already. I've been trying to get
this predict
function work, but somehow I keep on getting the same error.
Read the help
files, searched the internet, but I don't seem to get what
I'm doing wrong.
Anybody who has experience with this function? It's contained
in the package
e1071.
Thank you in advance
On Thu, Feb 19, 2009 at 2:16 PM, joris meys
<jorismeys at gmail.com> wrote:
Dear all,
I tried a simple naive Bayes classification on an
artificial dataset, but I
have troubles getting the predict function to work with the
specification. With type= "raw", it works perfectly, but
get following error :
Error in as.vector(x, mode) : invalid 'mode' argument
Data : mixture.train is a training set with 100 points
multivariate gaussian distributions (class 0 and class 1),
coordinates in a 2-dimensional space. Mixture.test is a
to +15 in both dimensions. Stupid data, but it's just to test.
Code :
Sigma <- matrix(c(10,3,3,2),2,2)
mixture.train <- cbind(mvrnorm(n=50, c(0, 2), Sigma),rep(0,50))
mixture.train <-
as.data.frame(rbind(mixture.train,cbind(mvrnorm(n=50, c(2,
0), Sigma),rep(1,50))))
names(mixture.train) <-c("X1","X2","Class")
X1 <- rep(seq(-15,15,by=1),31)
X2 <- rep(seq(-15,15,by=1),each = 31)
mixture.test <- data.frame(X1,X2)
Bayes.res <- naiveBayes(Class ~ X1 + X2, data=mixture.train)
pred.bayes <-predict(Bayes.res, cbind(mixture.test$X1,
mixture.test$X2),type="class")
Tried it also with pred.bayes <-predict(Bayes.res,
mixture.test,type="class"), but that gives the same effect.
am I missing something?
Kind regards
Joris Meys
University Ghent
[[alternative HTML version deleted]]