spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From felixcheung <...@git.apache.org>
Subject [GitHub] spark pull request #14392: [SPARK-16446] [SparkR] [ML] Gaussian Mixture Mode...
Date Tue, 16 Aug 2016 03:02:11 GMT
Github user felixcheung commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14392#discussion_r74869983
  
    --- Diff: R/pkg/R/mllib.R ---
    @@ -632,3 +659,110 @@ setMethod("predict", signature(object = "AFTSurvivalRegressionModel"),
               function(object, newData) {
                 return(dataFrame(callJMethod(object@jobj, "transform", newData@sdf)))
               })
    +
    +#' Multivariate Gaussian Mixture Model (GMM)
    +#'
    +#' Fits multivariate gaussian mixture model against a Spark DataFrame, similarly to R's
    +#' mvnormalmixEM(). 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.
    +#'
    +#' @param data SparkDataFrame for training
    +#' @param formula A symbolic description of the model to be fitted. Currently only a
few formula
    +#'                operators are supported, including '~', '.', ':', '+', and '-'.
    +#'                Note that the response variable of formula is empty in spark.gaussianMixture.
    +#' @param k Number of independent Gaussians in the mixture model.
    +#' @param maxIter Maximum iteration number
    +#' @param tol The convergence tolerance
    +#' @aliases spark.gaussianMixture,SparkDataFrame,formula-method
    +#' @return \code{spark.gaussianMixture} returns a fitted multivariate gaussian mixture
model
    +#' @rdname spark.gaussianMixture
    +#' @name spark.gaussianMixture
    +#' @seealso mixtools: \url{https://cran.r-project.org/web/packages/mixtools/}
    +#' @export
    +#' @examples
    +#' \dontrun{
    +#' sparkR.session()
    +#' library(mvtnorm)
    +#' set.seed(100)
    +#' a <- rmvnorm(4, c(0, 0))
    +#' b <- rmvnorm(6, c(3, 4))
    +#' data <- rbind(a, b)
    +#' df <- createDataFrame(as.data.frame(data))
    +#' model <- spark.gaussianMixture(df, ~ V1 + V2, k = 2)
    +#' summary(model)
    +#'
    +#' # fitted values on training data
    +#' fitted <- predict(model, df)
    +#' head(select(fitted, "V1", "prediction"))
    +#'
    +#' # save fitted model to input path
    +#' path <- "path/to/model"
    +#' write.ml(model, path)
    +#'
    +#' # can also read back the saved model and print
    +#' savedModel <- read.ml(path)
    +#' summary(savedModel)
    +#' }
    +#' @note spark.gaussianMixture since 2.1.0
    +#' @seealso \link{predict}, \link{read.ml}, \link{write.ml}
    +setMethod("spark.gaussianMixture", signature(data = "SparkDataFrame", formula = "formula"),
    +          function(data, formula, k = 2, maxIter = 100, tol = 0.01) {
    +            formula <- paste(deparse(formula), collapse = "")
    +            jobj <- callJStatic("org.apache.spark.ml.r.GaussianMixtureWrapper", "fit",
data@sdf,
    +                                formula, as.integer(k), as.integer(maxIter), tol)
    --- End diff --
    
    add `as.numeric(tol)` if we could, since tol is not in the signature


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message