[R] naive bayes help

Weiwei Shi helprhelp at gmail.com
Fri Jan 19 16:09:34 CET 2007


change the last line
m.pr<-predict(mydt.nb, mydata[,-1], type="class")

into
m.pr<-predict(mydt.nb, mydata[,-1], type="raw")

see
?naiveBayes
and
?predict.naiveBayes

Your "y" is a continous dependent variable.

HTH,


weiwei


On 1/19/07, leah martell <dimaiana at gmail.com> wrote:
>  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 at 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.
>


-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III



More information about the R-help mailing list