Github user felixcheung commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13690#discussion_r82512914
  
    --- Diff: R/pkg/R/mllib.R ---
    @@ -1427,3 +1447,185 @@ print.summary.KSTest <- function(x, ...) {
       cat(summaryStr, "\n")
       invisible(x)
     }
    +
    +#' Decision Tree Model for Regression and Classification
    +#'
    +#' \code{spark.decisionTree} fits a Decision Tree Regression model or 
Classification model on
    +#' a SparkDataFrame. Users can call \code{summary} to get a summary of the 
fitted Decision Tree
    +#' model, \code{predict} to make predictions on new data, and 
\code{write.ml}/\code{read.ml} to
    +#' save/load fitted models.
    +#' For more details, see 
\href{https://en.wikipedia.org/wiki/Decision_tree_learning}{Decision Tree}
    +#'
    +#' @param data a SparkDataFrame for training.
    +#' @param formula a symbolic description of the model to be fitted. 
Currently only a few formula
    +#'                operators are supported, including '~', ':', '+', and 
'-'.
    +#' @param type type of model to fit
    +#' @param maxDepth Maximum depth of the tree (>= 0).
    +#' @param maxBins Maximum number of bins used for discretizing continuous 
features and for choosing
    +#'                how to split on features at each node. More bins give 
higher granularity. Must be
    +#'                >= 2 and >= number of categories in any categorical 
feature. (default = 32)
    +#' @param ... additional arguments passed to the method.
    +#' @aliases spark.decisionTree,SparkDataFrame,formula-method
    +#' @return \code{spark.decisionTree} returns a fitted Decision Tree model.
    +#' @rdname spark.decisionTree
    +#' @name spark.decisionTree
    +#' @export
    +#' @examples
    +#' \dontrun{
    +#' df <- createDataFrame(longley)
    +#'
    +#' # fit a Decision Tree Regression Model
    +#' model <- spark.decisionTree(data, Employed ~ ., type = "regression", 
maxDepth = 5, maxBins = 16)
    +#'
    +#' # 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.decisionTree since 2.1.0
    +setMethod("spark.decisionTree", signature(data = "SparkDataFrame", formula 
= "formula"),
    +          function(data, formula, type = c("regression", "classification"),
    +                   maxDepth = 5, maxBins = 32 ) {
    +            type <- match.arg(type)
    +            formula <- paste(deparse(formula), collapse = "")
    +            switch(type,
    +                   regression =  {
    +                     jobj <- 
callJStatic("org.apache.spark.ml.r.DecisionTreeRegressorWrapper",
    +                                         "fit", data@sdf, formula, 
as.integer(maxDepth),
    +                                         as.integer(maxBins))
    +                     new("DecisionTreeRegressionModel", jobj = jobj)
    +                   },
    +                   classification = {
    +                     jobj <- 
callJStatic("org.apache.spark.ml.r.DecisionTreeClassifierWrapper",
    +                                         "fit", data@sdf, formula, 
as.integer(maxDepth),
    +                                         as.integer(maxBins))
    +                     new("DecisionTreeClassificationModel", jobj = jobj)
    +                   }
    +            )
    +          })
    +
    +# Makes predictions from a Decision Tree Regression model or
    +# a model produced by spark.decisionTree()
    +
    +#' @param newData a SparkDataFrame for testing.
    +#' @return \code{predict} returns a SparkDataFrame containing predicted 
labeled in a column named
    +#' "prediction"
    +#' @rdname spark.decisionTree
    +#' @export
    +#' @note predict(decisionTreeRegressionModel) since 2.1.0
    +setMethod("predict", signature(object = "DecisionTreeRegressionModel"),
    +          function(object, newData) {
    +            predict_internal(object, newData)
    +          })
    +
    +#' @rdname spark.decisionTree
    +#' @export
    +#' @note predict(decisionTreeClassificationModel) since 2.1.0
    +setMethod("predict", signature(object = "DecisionTreeClassificationModel"),
    +          function(object, newData) {
    +            predict_internal(object, newData)
    +          })
    +
    +#' Save the Decision Tree Regression model to the input path.
    +#'
    +#' @param object A fitted Decision tree regression model
    +#' @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.
    +#'
    +#' @aliases write.ml,DecisionTreeRegressionModel,character-method
    +#' @rdname spark.decisionTreeRegression
    +#' @export
    +#' @note write.ml(DecisionTreeRegressionModel, character) since 2.1.0
    +setMethod("write.ml", signature(object = "DecisionTreeRegressionModel", 
path = "character"),
    +          function(object, path, overwrite = FALSE) {
    +            write_internal(object, path, overwrite)
    +          })
    +
    +#' Save the Decision Tree Classification model to the input path.
    +#'
    +#' @param object A fitted Decision tree classification model
    +#' @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.
    +#'
    +#' @aliases write.ml,DecisionTreeClassificationModel,character-method
    +#' @rdname spark.decisionTreeClassification
    --- End diff --
    
    change to `@rdname spark.decisionTree`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to