spark.naiveBayes {SparkR} | R Documentation |
spark.naiveBayes
fits a Bernoulli naive Bayes model against a SparkDataFrame.
Users can call summary
to print a summary of the fitted model, predict
to make
predictions on new data, and write.ml
/read.ml
to save/load fitted models.
Only categorical data is supported.
spark.naiveBayes(data, formula, ...) ## S4 method for signature 'NaiveBayesModel' predict(object, newData) ## S4 method for signature 'NaiveBayesModel' summary(object, ...) ## S4 method for signature 'SparkDataFrame,formula' spark.naiveBayes(data, formula, smoothing = 1, ...) ## S4 method for signature 'NaiveBayesModel,character' write.ml(object, path, overwrite = FALSE)
data |
a |
formula |
a symbolic description of the model to be fitted. Currently only a few formula operators are supported, including '~', '.', ':', '+', and '-'. |
... |
additional argument(s) passed to the method. Currently only |
object |
a naive Bayes model fitted by |
newData |
a SparkDataFrame for testing. |
smoothing |
smoothing parameter. |
path |
the directory where the model is saved |
overwrite |
overwrites or not if the output path already exists. Default is FALSE which means throw exception if the output path exists. |
predict
returns a SparkDataFrame containing predicted labeled in a column named
"prediction"
summary
returns a list containing apriori
, the label distribution, and
tables
, conditional probabilities given the target label.
spark.naiveBayes
returns a fitted naive Bayes model.
predict(NaiveBayesModel) since 2.0.0
summary(NaiveBayesModel) since 2.0.0
spark.naiveBayes since 2.0.0
write.ml(NaiveBayesModel, character) since 2.0.0
e1071: https://cran.r-project.org/package=e1071
## Not run: data <- as.data.frame(UCBAdmissions) df <- createDataFrame(data) # fit a Bernoulli naive Bayes model model <- spark.naiveBayes(df, Admit ~ Gender + Dept, smoothing = 0) # get the summary of the model summary(model) # make predictions predictions <- predict(model, df) # save and load the model path <- "path/to/model" write.ml(model, path) savedModel <- read.ml(path) summary(savedModel) ## End(Not run)