devtools::install_github("LiArAu/NaBa") library(NaBa) library(Rcpp) library(e1071) library(naivebayes) library(microbenchmark) library(ggplot2)
data(mood) x=mood[,1:5] y=mood[,6] newdata=mood[1:200,1:5]
head(mood) dim(mood) head(newdata) dim(newdata)
NaBa
, e1071
and naivebayes
prior=NaBa::Info_prior(x,y) myresult_raw=NaBa::predict_naBa(prior,newdata,"raw") myresult_class=NaBa::predict_naBa(prior,newdata,"class") prior2=e1071::naiveBayes(x,y) e1071result_raw=predict(prior2,newdata,"raw") e1071result_class=predict(prior2,newdata,"class") prior3=naivebayes::naive_bayes(x,y) nbresult_raw=predict(prior3,newdata,"prob") nbresult_class=predict(prior3,newdata,"class")
all.equal(myresult_raw,e1071result_raw) all.equal(myresult_class,e1071result_class)
tm <- microbenchmark::microbenchmark( NaBa_result=NaBa::predict_naBa(prior,newdata,"raw"), e1071_result=predict(prior2,newdata,"raw"), naivebayes_result=predict(prior3,newdata,"prob")) ggplot2::autoplot(tm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.