Learn R Programming

h2o (version 2.8.4.4)

h2o.naiveBayes: H2O: Naive Bayes Classifier

Description

Builds gradient boosted classification trees, and gradient boosted regression trees on a parsed data set.

Usage

h2o.naiveBayes(x, y, data, key = "", laplace = 0, dropNACols = FALSE)

Arguments

x
A vector containing the names of the predictors in the model.
y
The name of the response variable in the model.
data
An H2OParsedData (version = 2) object containing the variables in the model.
key
(Optional) The unique hex key assigned to the resulting model. If none is given, a key will automatically be generated.
laplace
(Optional) A positive number controlling Laplace smoothing. The default (0) disables Laplace smoothing.
dropNACols
(Optional) A logical value indicating whether to drop predictor columns with >= 20% NAs.

Value

  • An object of class H2ONBModel with slots key, data, and model, where the last is a list of the following components:
  • laplaceA positive number controlling Laplace smoothing. The default (0) disables Laplace smoothing.
  • levelsCategorical levels of the dependent variable.
  • aprioriTotal occurrences of each level of the dependent variable.
  • apriori_probA-priori class distribution for the dependent variable.
  • tablesA list of tables, one for each predictor variable. For categorical predictors, the table displays, for each attribute level, the conditional probabilities given the target class. For numeric predictors, the table gives, for each target class, the mean and standard deviation of the variable.

Details

The naive Bayes classifier assumes independence between predictor variables conditional on the response, and a Gaussian distribution of numeric predictors with mean and standard deviation computed from the training dataset.

When building a naive Bayes classifier, every row in the training dataset that contains at least one NA will be skipped completely. If the test dataset has missing values, then those predictors are omitted in the probability calculation during prediction.

See Also

For more information see: http://docs.h2o.ai

Examples

Run this code
library(h2o)
localH2O = h2o.init()

# Build naive Bayes classifier with categorical predictors
votesPath = system.file("extdata", "housevotes.csv", package="h2o")
votes.hex = h2o.importFile(localH2O, path = votesPath, header = TRUE)
summary(votes.hex)
h2o.naiveBayes(y = 1, x = 2:17, data = votes.hex, laplace = 3)

# Build naive Bayes classifier with numeric predictors
irisPath = system.file("extdata", "iris.csv", package="h2o")
iris.hex = h2o.importFile(localH2O, path = irisPath)
h2o.naiveBayes(y = 5, x = 1:4, data = iris.hex)

Run the code above in your browser using DataLab