knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

NaiveBayes

Travis build status

Codecov test coverage

This is a homework assignment of BIOSTAT625 at the Univeristy of Michigan, Ann Arbor.

The NaiveBayes package provides an efficient implementation of the popular Naive Bayes classifier. This package is efficient, user friendly and written in base.R and Rcpp. Like many other classifier packages, the general function NaiveBayes detects the class of each feature in the dataset. Predict function uses a NaiveBayes model and a new data set to create the classifications. This can either be the raw probabilities generated by the NaiveBayes model or the classes themselves.

Installation

You can download and install NaiveBayes with:

library(devtools)
devtools::install_github("sidiwang/NaiveBayes", build_vignettes = T)
library(NaiveBayes)

The vignettes of this package contains very detailed infomation on "What is Naive Bayes", "How to implement Naive Bayes", "The pros and cons of Naive Bayes" and how numerical underflow is handled during calculation. Various examples on how to use this package, and a performance comparison against the naiveBayes function in package e1071 were also included. Given the NaiveBayes function was partially written in Rcpp and vectorized some calculations in matrix form, our performance, in general, is better in efficiency and need less memory allocation.

Please use this code to check the vignettes.

browseVignettes("NaiveBayes")

Example

This is a basic example which shows you how to solve a common problem:

library(NaiveBayes)
## load data, and define X and Y
data("HouseVotes84")
x = HouseVotes84[, -c(1,9:17)]
y = HouseVotes84[, 1]

# fit the model
mymodel = NaiveBayes::NaiveBayes(x, y)
# check output
mymodel
# prediction, here we predicted on the original training dataset for simplicity purpose, but you can always feed new dataset into the function.
prediction = predict(mymodel, x)
# check first 10 predictions
prediction[1:10]

Limitations and reminders:



sidiwang/NaiveBayes documentation built on Nov. 26, 2019, 9 a.m.