[R] help on naivebayes function in R
Max Kuhn
mxkuhn at gmail.com
Wed Jun 30 18:07:20 CEST 2010
So...
You really should give the results of sessionInfo().
There are (at least) two naive Bayes functions. I'm assuming that you
are using the one in klaR.
Look at the manual page ? predict.NaiveBayes: the output is "A list
with the conditional a-posterior probabilities for each class and the
estimated class are returned." The example is short, but you could see
that
> data(iris)
> m <- NaiveBayes(Species ~ ., data = iris)
> str(predict(m))
List of 2
$ class : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1
1 1 1 1 ...
..- attr(*, "names")= chr [1:150] "1" "2" "3" "4" ...
$ posterior: num [1:150, 1:3] 1 1 1 1 1 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:150] "1" "2" "3" "4" ...
.. ..$ : chr [1:3] "setosa" "versicolor" "virginica"
You can get there via something like:
> table(iris$Species, predict(m)$class)
setosa versicolor virginica
setosa 50 0 0
versicolor 0 47 3
virginica 0 3 47
Max
On Wed, Jun 30, 2010 at 9:16 AM, Aadhithya <sistaadhi at gmail.com> wrote:
>
> Hi,
> I have written a code in R for classifying microarray data using naive
> bayes, the code is given below:
> library(e1071)
> train<-read.table("Z:/Documents/train.txt",header=T);
> test<-read.table("Z:/Documents/test.txt",header=T);
> cl <- c(c(rep("ALL",10), rep("AML",10)));
> cl <- factor(cl)
> model <- NaiveBayes(train,cl);
> pred<-predict(model,test,type = "raw");
> table(pred,cl);
> everything is working fine I am able to build the model and predict also but
> I am not able to get the confusion matrix using table function.its giving me
> the following error when I execute the line "table(pred,cl)"
> Error in sort.list(unique.default(x), na.last = TRUE) :
> 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?
> I am not sure where I am going wrong. I want the confusion matrix using
> table function but I am not able to get it . Please help me . I will be
> really grateful .Thanks in advance.
> -Aadhithya
>
> --
> View this message in context: http://r.789695.n4.nabble.com/help-on-naivebayes-function-in-R-tp2272720p2272720.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Max
More information about the R-help
mailing list