Skip to content

Commit

Permalink
[SPARK-20906][SPARKR] Add API doc example for Constrained Logistic Re…
Browse files Browse the repository at this point in the history
…gression

## What changes were proposed in this pull request?

doc only changes

## How was this patch tested?

manual

Author: Felix Cheung <felixcheung_m@hotmail.com>

Closes #20380 from felixcheung/rclrdoc.

(cherry picked from commit e18d6f5)
Signed-off-by: Felix Cheung <felixcheung@apache.org>
  • Loading branch information
felixcheung authored and Felix Cheung committed Jan 24, 2018
1 parent 17317c8 commit 4336e67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 14 additions & 1 deletion R/pkg/R/mllib_classification.R
Expand Up @@ -279,11 +279,24 @@ function(object, path, overwrite = FALSE) {
#' savedModel <- read.ml(path)
#' summary(savedModel)
#'
#' # multinomial logistic regression
#' # binary logistic regression against two classes with
#' # upperBoundsOnCoefficients and upperBoundsOnIntercepts
#' ubc <- matrix(c(1.0, 0.0, 1.0, 0.0), nrow = 1, ncol = 4)
#' model <- spark.logit(training, Species ~ .,
#' upperBoundsOnCoefficients = ubc,
#' upperBoundsOnIntercepts = 1.0)
#'
#' # multinomial logistic regression
#' model <- spark.logit(training, Class ~ ., regParam = 0.5)
#' summary <- summary(model)
#'
#' # multinomial logistic regression with
#' # lowerBoundsOnCoefficients and lowerBoundsOnIntercepts
#' lbc <- matrix(c(0.0, -1.0, 0.0, -1.0, 0.0, -1.0, 0.0, -1.0), nrow = 2, ncol = 4)
#' lbi <- as.array(c(0.0, 0.0))
#' model <- spark.logit(training, Species ~ ., family = "multinomial",
#' lowerBoundsOnCoefficients = lbc,
#' lowerBoundsOnIntercepts = lbi)
#' }
#' @note spark.logit since 2.1.0
setMethod("spark.logit", signature(data = "SparkDataFrame", formula = "formula"),
Expand Down
10 changes: 5 additions & 5 deletions R/pkg/tests/fulltests/test_mllib_classification.R
Expand Up @@ -124,7 +124,7 @@ test_that("spark.logit", {
# Petal.Width 0.42122607
# nolint end

# Test multinomial logistic regression againt three classes
# Test multinomial logistic regression against three classes
df <- suppressWarnings(createDataFrame(iris))
model <- spark.logit(df, Species ~ ., regParam = 0.5)
summary <- summary(model)
Expand Down Expand Up @@ -196,7 +196,7 @@ test_that("spark.logit", {
#
# nolint end

# Test multinomial logistic regression againt two classes
# Test multinomial logistic regression against two classes
df <- suppressWarnings(createDataFrame(iris))
training <- df[df$Species %in% c("versicolor", "virginica"), ]
model <- spark.logit(training, Species ~ ., regParam = 0.5, family = "multinomial")
Expand All @@ -208,7 +208,7 @@ test_that("spark.logit", {
expect_true(all(abs(versicolorCoefsR - versicolorCoefs) < 0.1))
expect_true(all(abs(virginicaCoefsR - virginicaCoefs) < 0.1))

# Test binomial logistic regression againt two classes
# Test binomial logistic regression against two classes
model <- spark.logit(training, Species ~ ., regParam = 0.5)
summary <- summary(model)
coefsR <- c(-6.08, 0.25, 0.16, 0.48, 1.04)
Expand Down Expand Up @@ -239,7 +239,7 @@ test_that("spark.logit", {
prediction2 <- collect(select(predict(model2, df2), "prediction"))
expect_equal(sort(prediction2$prediction), c("0.0", "0.0", "0.0", "0.0", "0.0"))

# Test binomial logistic regression againt two classes with upperBoundsOnCoefficients
# Test binomial logistic regression against two classes with upperBoundsOnCoefficients
# and upperBoundsOnIntercepts
u <- matrix(c(1.0, 0.0, 1.0, 0.0), nrow = 1, ncol = 4)
model <- spark.logit(training, Species ~ ., upperBoundsOnCoefficients = u,
Expand All @@ -252,7 +252,7 @@ test_that("spark.logit", {
expect_error(spark.logit(training, Species ~ ., upperBoundsOnCoefficients = as.array(c(1, 2)),
upperBoundsOnIntercepts = 1.0))

# Test binomial logistic regression againt two classes with lowerBoundsOnCoefficients
# Test binomial logistic regression against two classes with lowerBoundsOnCoefficients
# and lowerBoundsOnIntercepts
l <- matrix(c(0.0, -1.0, 0.0, -1.0), nrow = 1, ncol = 4)
model <- spark.logit(training, Species ~ ., lowerBoundsOnCoefficients = l,
Expand Down

0 comments on commit 4336e67

Please sign in to comment.