On Wednesday 06 May 2009, Tim LIU wrote: > I am wondering if anybody here have a simple example in R for Naive > Bayes. > > For example, I can do k-means clustering on the "iris" data - > > data(iris) > cl <- kmeans(iris[,1:4], 3) > cl$cluster > cbind(1:150,iris$Species) > > =========== > > But how to do Naive Bayes classification in the same "iris" data? > > Many thanks!
# start here: help.search('bayes') # in which you will find: e1071::naiveBayes # which means: library(e1071) ?naiveBayes # and compared to your example: cl <- kmeans(iris[,1:4], 3) table(cl$cluster, iris[,5]) m <- naiveBayes(iris[,1:4], iris[,5]) table(predict(m, iris[,1:4]), iris[,5]) Dylan -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 ______________________________________________ R-help@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.