devtools::install_github("LiArAu/NaBa")
library(NaBa)
library(Rcpp)
library(e1071)
library(naivebayes)
library(microbenchmark)
library(ggplot2)

Have a look at the test data

data(mood)
x=mood[,1:5]
y=mood[,6]
newdata=mood[1:200,1:5]
head(mood)
dim(mood)
head(newdata)
dim(newdata)

Obtain prior information and make predictions using 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")

Compare if the predictions of NaBa are the same as e1071:

all.equal(myresult_raw,e1071result_raw)
all.equal(myresult_class,e1071result_class)

Compare efficiency of predict function with other packages:

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)


LiArAu/NaBa documentation built on Nov. 27, 2019, 9:28 p.m.