Package naivebayes. R topics documented: January 3, Type Package. Title High Performance Implementation of the Naive Bayes Algorithm

Similar documents
Package misclassglm. September 3, 2016

Package glmnetutils. August 1, 2017

Package rpst. June 6, 2017

Package ebmc. August 29, 2017

Package C50. December 1, 2017

Package fastdummies. January 8, 2018

Package PrivateLR. March 20, 2018

Package sankey. R topics documented: October 22, 2017

Package rferns. November 15, 2017

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package areaplot. October 18, 2017

Package RandPro. January 10, 2018

Package arulescba. April 24, 2018

Package fasttextr. May 12, 2017

Package maboost. R topics documented: February 20, 2015

Package lspls. July 27, 2018

Package statip. July 31, 2018

Package tidyimpute. March 5, 2018

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package CausalImpact

Package kerasformula

Package Cubist. December 2, 2017

Package glmmml. R topics documented: March 25, Encoding UTF-8 Version Date Title Generalized Linear Models with Clustering

Package vinereg. August 10, 2018

Package ICEbox. July 13, 2017

Package rvinecopulib

Package ConvergenceClubs

Package gensemble. R topics documented: February 19, 2015

Package spark. July 21, 2017

Package TVsMiss. April 5, 2018

Package obliquerf. February 20, Index 8. Extract variable importance measure

Package caretensemble

Package ranger. November 10, 2015

Package balance. October 12, 2018

Package MTLR. March 9, 2019

Package narray. January 28, 2018

Package intccr. September 12, 2017

Package kirby21.base

Package kernelfactory

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package signalhsmm. August 29, 2016

Package SSLASSO. August 28, 2018

Package ridge. R topics documented: February 15, Title Ridge Regression with automatic selection of the penalty parameter. Version 2.

Package datasets.load

Package nonlinearicp

Package BKPC. March 13, 2018

Package canvasxpress

Package reghelper. April 8, 2017

Package cosinor. February 19, 2015

Package pairsd3. R topics documented: August 29, Title D3 Scatterplot Matrices Version 0.1.0

Package glinternet. June 15, 2018

Package svalues. July 15, 2018

Package cwm. R topics documented: February 19, 2015

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package ArCo. November 5, 2017

The grplasso Package

Package randomforest.ddr

Package colf. October 9, 2017

Package crossword.r. January 19, 2018

Package gtrendsr. August 4, 2018

Package GWRM. R topics documented: July 31, Type Package

Package io. January 15, 2018

Package svmpath. R topics documented: August 30, Title The SVM Path Algorithm Date Version Author Trevor Hastie

Package desirability

Package preprocomb. June 26, 2016

Package hgam. February 20, 2015

Package missforest. February 15, 2013

Package PCADSC. April 19, 2017

Package epitab. July 4, 2018

Package logicfs. R topics documented:

Package autocogs. September 22, Title Automatic Cognostic Summaries Version 0.1.1

Package jstree. October 24, 2017

Package sparsereg. R topics documented: March 10, Type Package

Package RaPKod. February 5, 2018

Package breakdown. June 14, 2018

Package gtrendsr. October 19, 2017

Package mdftracks. February 6, 2017

Package tibble. August 22, 2017

Package survivalmpl. December 11, 2017

Package Numero. November 24, 2018

Package rfsa. R topics documented: January 10, Type Package

Package dgo. July 17, 2018

Package optimus. March 24, 2017

Package gppm. July 5, 2018

Package gifti. February 1, 2018

Package RLT. August 20, 2018

Package polywog. April 20, 2018

Package manet. September 19, 2017

Package PTE. October 10, 2017

Package listdtr. November 29, 2016

Package automl. September 13, 2018

Package qboxplot. November 12, qboxplot... 1 qboxplot.stats Index 5. Quantile-Based Boxplots

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package nodeharvest. June 12, 2015

Package AnDE. R topics documented: February 19, 2015

Package repec. August 31, 2018

Package gibbs.met. February 19, 2015

Package clustmixtype

Package reval. May 26, 2015

Package gridgraphics

Transcription:

Package naivebayes January 3, 2018 Type Package Title High Performance Implementation of the Naive Bayes Algorithm Version 0.9.2 Author Michal Majka Maintainer Michal Majka <michalmajka@hotmail.com> Description High performance implementation of the Naive Bayes algorithm. URL http://github.com/majkamichal/naivebayes BugReports http://github.com/majkamichal/naivebayes/issues License GPL-2 Encoding UTF-8 NeedsCompilation no Repository CRAN Date/Publication 2018-01-03 04:41:25 UTC R topics documented: naive_bayes......................................... 2 plot.naive_bayes...................................... 4 predict.naive_bayes..................................... 5 tables............................................ 6 Index 8 1

2 naive_bayes naive_bayes Naive Bayes Classifier Description naive_bayes is used to fit Naive Bayes model in which predictors are assumed to be independent within each class label. Usage ## Default S3 method: naive_bayes(x, y, prior = NULL, laplace = 0, usekernel = FALSE,...) ## S3 method for class 'formula' naive_bayes(formula, data, prior = NULL, laplace = 0, usekernel = FALSE, subset, na.action = stats::na.pass,...) Arguments x y formula data Details laplace usekernel prior subset na.action numeric matrix or dataframe with categorical (character/factor/logical) or metric (numeric) predictors. class vector (character/factor/logical). an object of class "formula" (or one that can be coerced to "formula") of the form class ~ predictors (class has to be a factor/character/logical). numeric matrix or dataframe with categorical (character/factor/logical) or metric (numeric) predictors. value used for Laplace smoothing. Defaults to 0 (no Laplace smoothing). logical; if TRUE, density is used to estimate the densities of metric predictors. vector with prior probabilities of the classes. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels. an optional vector specifying a subset of observations to be used in the fitting process. a function which indicates what should happen when the data contain NAs. By default (na.pass), missing values are not removed from the data and are then omited while constructing tables. Alternatively, na.omit can be used to exclude rows with at least one missing value before constructing tables.... other graphical parameters to density (na.rm defaults to TRUE). Metric predictors are handled by assuming that they follow Gaussian distribution, given the class label. Alternatively, kernel density estimation can be used to estimate their class-conditional distributions. Missing values are not included into constructing tables. Logical variables are treated as categorical variables.

naive_bayes 3 Value naive_bayes returns an object of class "naive_bayes" which is a list with following components: data tables prior laplace levels usekernel call list with two components: x (dataframe with predictors) and y (class variable). list of tables. For each categorical predictor a table with class-conditional probabilities and for each metric predictor a table with means and standard deviations or density objects for each class. numeric vector with prior probabilities. value of Laplace smoothing. character vector with values of the class variable. logical; TRUE, if the density was used for estimating densities of numeric variables. the call that produced this object. Author(s) See Also Michal Majka, <michalmajka@hotmail.com> predict.naive_bayes, plot.naive_bayes, tables Examples data(iris) nb <- naive_bayes(species ~., data = iris) plot(nb) nb_kernel <- naive_bayes(x = iris[-5], y = iris[,5], usekernel = TRUE) plot(nb_kernel) ## Not run: vars <- 10 rows <- 500000 y <- sample(c("a", "b"), rows, TRUE) # Only categorical variables X1 <- as.data.frame(matrix(sample(letters[5:9], vars * rows, TRUE), ncol = vars)) nb_cat <- naive_bayes(x = X1, y = y) nb_cat system.time(pred2 <- predict(nb_cat, X1)) # Only numeric variables X2 <- as.data.frame(matrix(rnorm(vars * rows), ncol = vars)) nb_num <- naive_bayes(x = X2, y = y) nb_num system.time(pred2 <- predict(nb_num, X2))

4 plot.naive_bayes ## End(Not run) plot.naive_bayes Plot Method for naive_bayes Object Description Plot method for objects of class "naive_bayes" designed for a quick look at the marginal probabilities of predictor variables given the class. Usage ## S3 method for class 'naive_bayes' plot(x, which = NULL, ask = FALSE, legend = TRUE, legend.box = FALSE, arg.num = list(), arg.cat = list(),...) Arguments x which ask legend legend.box arg.num arg.cat... not used. object of class inheriting from "naive_bayes". variables to be plotted (all by default). This can be any valid indexing vector or vector containing names of variables. logical; if TRUE, the user is asked before each plot, see par(ask=.). logical; if TRUE a legend will be be plotted. logical; if TRUE a box will be drawn around the legend. other parameters to be passed as a named list to matplot. other parameters to be passed as a named list to mosaicplot. Details Conditional probabilities are visualised by matplot (for metric predictors) and mosaicplot (for categorical predictors). In case of non parametric estimation of class-conditional densities, the bandwidths are reported. Nothing is returned. Author(s) Michal Majka, <michalmajka@hotmail.com> See Also naive_bayes, predict.naive_bayes, tables

predict.naive_bayes 5 Examples data(iris) iris2 <- cbind(iris, New = sample(letters[1:3], 150, TRUE)) nb <- naive_bayes(species ~., data = iris2) plot(nb, ask = TRUE) plot(nb, which = c(1, 2), ask = TRUE, arg.num = list(col = 1:3, lty = 1, main = "Naive Bayes Plot")) plot(nb, which = "New", arg.cat = list(color = 4:7)) predict.naive_bayes Predict Method for naive_bayes Objects Description Classification based on Naive Bayes models. Usage ## S3 method for class 'naive_bayes' predict(object, newdata = NULL, type = c("class","prob"), threshold = 0.001,...) Arguments object newdata type threshold... not used. object of class inheriting from "naive_bayes". numeric matrix or dataframe with categorical (character/factor/logical) or metric (numeric) predictors. if "class", new data points are classified according to the highest posterior probabilities. If "prob", the posterior probabilities for each class are returned. value by which zero probabilities corresponding to metric variables are replaced (zero probabilities corresponding to categorical variables can be handled with Laplace smoothing). Details Computes conditional posterior probabilities for each class using the Bayes rule. If no new data is provided, the data from the object is used. Logical variables are treated as categorical variables. Predictors with missing values are not included into the computation of posterior probabilities. Value predict.naive_bayes returns a factor with class corresponding to the maximal conditional posterior probability or a matrix with conditional posterior probabilities for each class.

6 tables Author(s) Michal Majka, <michalmajka@hotmail.com> See Also naive_bayes, plot.naive_bayes, tables Examples ind_iris <- sample(1:nrow(iris), size = round(0.3 * nrow(iris))) iris_train <- iris[-ind_iris, ] iris_test <- iris[ind_iris, ] nb_iris <- naive_bayes(species ~., iris_train) predict(nb_iris, iris_test) head(predict(nb_iris, iris_test, type = "prob")) ## Not run: vars <- 10 rows <- 500000 y <- sample(c("a", "b"), rows, TRUE) # Only categorical variables X1 <- as.data.frame(matrix(sample(letters[5:9], vars * rows, TRUE), ncol = vars)) nb_cat <- naive_bayes(x = X1, y = y) nb_cat system.time(pred2 <- predict(nb_cat, X1)) # Only numeric variables X2 <- as.data.frame(matrix(rnorm(vars * rows), ncol = vars)) nb_num <- naive_bayes(x = X2, y = y) nb_num system.time(pred2 <- predict(nb_num, X2)) ## End(Not run) tables Browse Tables of Naive Bayes Classifier Description Auxiliary function for "naive_bayes" objects for easy browsing tables. Usage tables(object, which = NULL)

tables 7 Arguments object which object of class inheriting from "naive_bayes". tables to be showed (all by default). This can be any valid indexing vector or vector containing names of variables. Details Value Default print method for "naive_bayes" objects shows at most five first tables. The auxiliary function tables returns by default all tables. list with tables. Author(s) See Also Michal Majka, <michalmajka@hotmail.com> naive_bayes, predict.naive_bayes, plot.naive_bayes Examples data(iris) nb <- naive_bayes(species ~., data = iris) tables(nb, "Sepal.Length") tables(nb, 1:2)

Index density, 2, 3 legend, 4 matplot, 4 mosaicplot, 4 na.omit, 2 na.pass, 2 naive_bayes, 2, 4, 6, 7 par, 4 plot.naive_bayes, 3, 4, 6, 7 predict.naive_bayes, 3, 4, 5, 7 tables, 3, 4, 6, 6 8