[R] naive bayes help

From: leah martell <dimaiana_at_gmail.com>
Date: Fri 19 Jan 2007 - 10:49:03 GMT


 Hello

I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance.

##### create data
set.seed(10)

n <- 200                     # number of training points
n.test <- 200               # number of test points
p<-2                            # dimension of input space
z <- matrix(rnorm((n+n.test)*p),ncol=p)
x <- matrix(0,nrow=n+n.test,ncol=p)
for (i in 1:p)
  x[,i] <- z%*%rnorm(p)
truecoef <- c(1,2)
prob1 <- exp(x%*%truecoef)/(1+exp(x%*%truecoef))
# prob is the true probability of class 1
y <- rbinom(n+n.test,1,prob1)
# separate the data into train and test sets
mydata <- data.frame(y=y[1:n],x=x[1:n,]) mydata.test <- data.frame(y=y[n+(1:n.test)],x=x[n+(1: n.test),])
##########################

library(e1071)
mydt.nb<-naiveBayes(y~ ., data=mydata)
m.pr<-predict(mydt.nb, mydata[,-1], type="class")

regards,
Leah

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Jan 19 21:54:30 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 19 Jan 2007 - 15:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.