Skip to content
Snippets Groups Projects
Commit 4a40d43b authored by Xiangrui Meng's avatar Xiangrui Meng
Browse files

[SPARK-16142][R] group naiveBayes method docs in a single Rd

## What changes were proposed in this pull request?

This PR groups `spark.naiveBayes`, `summary(NB)`, `predict(NB)`, and `write.ml(NB)` into a single Rd.

## How was this patch tested?

Manually checked generated HTML doc. See attached screenshots.

![screen shot 2016-06-23 at 2 11 00 pm](https://cloud.githubusercontent.com/assets/829644/16320452/a5885e92-394c-11e6-994f-2ab5cddad86f.png)

![screen shot 2016-06-23 at 2 11 15 pm](https://cloud.githubusercontent.com/assets/829644/16320455/aad1f6d8-394c-11e6-8ef4-13bee989f52f.png)

Author: Xiangrui Meng <meng@databricks.com>

Closes #13877 from mengxr/SPARK-16142.
parent 14bc5a7f
No related branches found
No related tags found
No related merge requests found
......@@ -218,9 +218,10 @@ print.summary.GeneralizedLinearRegressionModel <- function(x, ...) {
# Makes predictions from a generalized linear model produced by glm() or spark.glm(),
# similarly to R's predict().
#'
#' @param newData SparkDataFrame for testing
#' @return \code{predict} returns a SparkDataFrame containing predicted labels in a column named "prediction"
#' @return \code{predict} returns a SparkDataFrame containing predicted labels in a column named
#' "prediction"
#' @rdname spark.glm
#' @export
#' @note predict(GeneralizedLinearRegressionModel) since 1.5.0
......@@ -229,41 +230,26 @@ setMethod("predict", signature(object = "GeneralizedLinearRegressionModel"),
return(dataFrame(callJMethod(object@jobj, "transform", newData@sdf)))
})
#' Predicted values based on model
#'
#' Makes predictions from a naive Bayes model or a model produced by spark.naiveBayes(),
#' similarly to R package e1071's predict.
#'
#' @param object A fitted naive Bayes model
#' @rdname predict
# Makes predictions from a naive Bayes model or a model produced by spark.naiveBayes(),
# similarly to R package e1071's predict.
#' @rdname spark.naiveBayes
#' @return \code{predict} returns a SparkDataFrame containing predicted labeled in a column named
#' "prediction"
#' @export
#' @examples
#' \dontrun{
#' model <- spark.naiveBayes(trainingData, y ~ x)
#' predicted <- predict(model, testData)
#' showDF(predicted)
#'}
#' @note predict(NaiveBayesModel) since 2.0.0
setMethod("predict", signature(object = "NaiveBayesModel"),
function(object, newData) {
return(dataFrame(callJMethod(object@jobj, "transform", newData@sdf)))
})
#' Get the summary of a naive Bayes model
#'
#' Returns the summary of a naive Bayes model produced by spark.naiveBayes(),
#' similarly to R's summary().
#'
#' @param object A fitted MLlib model
#' @return a list containing 'apriori', the label distribution, and 'tables', conditional
# probabilities given the target label
#' @rdname summary
# Returns the summary of a naive Bayes model produced by \code{spark.naiveBayes}
#' @param object A naive Bayes model fitted by \code{spark.naiveBayes}
#' @return \code{summary} returns a list containing \code{apriori}, the label distribution, and
#' \code{tables}, conditional probabilities given the target label
#' @rdname spark.naiveBayes
#' @export
#' @examples
#' \dontrun{
#' model <- spark.naiveBayes(trainingData, y ~ x)
#' summary(model)
#'}
#' @note summary(NaiveBayesModel) since 2.0.0
setMethod("summary", signature(object = "NaiveBayesModel"),
function(object, ...) {
......@@ -390,23 +376,41 @@ setMethod("predict", signature(object = "KMeansModel"),
return(dataFrame(callJMethod(object@jobj, "transform", newData@sdf)))
})
#' Fit a Bernoulli naive Bayes model
#' Naive Bayes Models
#'
#' Fit a Bernoulli naive Bayes model on a Spark DataFrame (only categorical data is supported).
#' \code{spark.naiveBayes} fits a Bernoulli naive Bayes model against a SparkDataFrame.
#' Users can call \code{summary} to print a summary of the fitted model, \code{predict} to make
#' predictions on new data, and \code{write.ml}/\code{read.ml} to save/load fitted models.
#' Only categorical data is supported.
#'
#' @param data SparkDataFrame for training
#' @param data A \code{SparkDataFrame} of observations and labels for model fitting
#' @param formula A symbolic description of the model to be fitted. Currently only a few formula
#' operators are supported, including '~', '.', ':', '+', and '-'.
#' @param smoothing Smoothing parameter
#' @return a fitted naive Bayes model
#' @return \code{spark.naiveBayes} returns a fitted naive Bayes model
#' @rdname spark.naiveBayes
#' @name spark.naiveBayes
#' @seealso e1071: \url{https://cran.r-project.org/web/packages/e1071/}
#' @export
#' @examples
#' \dontrun{
#' df <- createDataFrame(infert)
#'
#' # fit a Bernoulli naive Bayes model
#' model <- spark.naiveBayes(df, education ~ ., 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)
#' }
#' @note spark.naiveBayes since 2.0.0
setMethod("spark.naiveBayes", signature(data = "SparkDataFrame", formula = "formula"),
function(data, formula, smoothing = 1.0, ...) {
......@@ -416,25 +420,15 @@ setMethod("spark.naiveBayes", signature(data = "SparkDataFrame", formula = "form
return(new("NaiveBayesModel", jobj = jobj))
})
#' Save fitted MLlib model to the input path
#'
#' Save the Bernoulli naive Bayes model to the input path.
#'
#' @param object A fitted Bernoulli naive Bayes model
# Saves the Bernoulli naive Bayes model to the input path.
#' @param path The directory where the model is saved
#' @param overwrite Overwrites or not if the output path already exists. Default is FALSE
#' which means throw exception if the output path exists.
#'
#' @rdname write.ml
#' @name write.ml
#' @rdname spark.naiveBayes
#' @export
#' @examples
#' \dontrun{
#' df <- createDataFrame(infert)
#' model <- spark.naiveBayes(df, education ~ ., smoothing = 0)
#' path <- "path/to/model"
#' write.ml(model, path)
#' }
#' @seealso \link{read.ml}
#' @note write.ml(NaiveBayesModel, character) since 2.0.0
setMethod("write.ml", signature(object = "NaiveBayesModel", path = "character"),
function(object, path, overwrite = FALSE) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment