[R] Regarding naive baysian classifier in R

Hans W Borchers hwborchers at googlemail.com
Tue Aug 31 13:48:23 CEST 2010

Vishnampettai <akron_aadhithya <at> yahoo.com> writes:
> Hi,
>   I have a small doubt regarding naive Bayes. I am able to classify the
> data's properly but i am just stuck up with how to get the probability
> values for naive bayes. In the case of SVM we have "attr" function that
> helps in displaying the probability values. Is there any function similar to
> "attr" in naive Bayes that can be used for displaying the attribute values.

Some time ago I wrote my own naive Bayes classifier as I was unsatisfied with
the speed of other implementations for larger data sets. My predict function
returns an 'accuracy' with every input item based on the standard calculation.

If you like I can send it to you as I am also interested in more test cases,
though I did some tests comparing it with results from 'e1071::naiveBayes'.

Hans Werner

P. S.:  What are you doing with "decision.values=TRUE, probability=TRUE"?
I can't find those in the documentation for naiveBayes. I assume you don't
get an error because the "..." catches all these unused parameters.

> my code is given below:
> library(e1071)
> train<-read.table("...",header=T);
> test<-read.table("...",header=T);
> length(test);
> cl <- c(c(rep("ALL",10), rep("AML",10)));
> cl <- factor(cl)
> model <- naiveBayes(t(train),cl);
> pred<-predict(model, t(test),decision.values=TRUE,probability=TRUE)
> attr(pred,"probabilities");
> table(pred,t(cl));

More information about the R-help mailing list