-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-21622][ML][SparkR] Support offset in SparkR GLM #18831
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ setClass("IsotonicRegressionModel", representation(jobj = "jobj")) | |
#' @param maxIter integer giving the maximal number of IRLS iterations. | ||
#' @param weightCol the weight column name. If this is not set or \code{NULL}, we treat all instance | ||
#' weights as 1.0. | ||
#' @param offsetCol the offset column name. If this is not set or empty, we treat all instance offsets | ||
#' as 0.0. The feature specified as offset has a constant coefficient of 1.0. | ||
#' @param regParam regularization parameter for L2 regularization. | ||
#' @param var.power the power in the variance function of the Tweedie distribution which provides | ||
#' the relationship between the variance and mean of the distribution. Only | ||
|
@@ -125,7 +127,7 @@ setClass("IsotonicRegressionModel", representation(jobj = "jobj")) | |
#' @seealso \link{glm}, \link{read.ml} | ||
setMethod("spark.glm", signature(data = "SparkDataFrame", formula = "formula"), | ||
function(data, formula, family = gaussian, tol = 1e-6, maxIter = 25, weightCol = NULL, | ||
regParam = 0.0, var.power = 0.0, link.power = 1.0 - var.power, | ||
offsetCol = NULL, regParam = 0.0, var.power = 0.0, link.power = 1.0 - var.power, | ||
stringIndexerOrderType = c("frequencyDesc", "frequencyAsc", | ||
"alphabetDesc", "alphabetAsc")) { | ||
|
||
|
@@ -159,10 +161,16 @@ setMethod("spark.glm", signature(data = "SparkDataFrame", formula = "formula"), | |
weightCol <- as.character(weightCol) | ||
} | ||
|
||
if (!is.null(offsetCol) && offsetCol == "") { | ||
offsetCol <- NULL | ||
} else if (!is.null(offsetCol)) { | ||
offsetCol <- as.character(offsetCol) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps
not sure if you want to cover other cases when offsetCol cannot be coerced - eg. NA |
||
|
||
# For known families, Gamma is upper-cased | ||
jobj <- callJStatic("org.apache.spark.ml.r.GeneralizedLinearRegressionWrapper", | ||
"fit", formula, data@sdf, tolower(family$family), family$link, | ||
tol, as.integer(maxIter), weightCol, regParam, | ||
tol, as.integer(maxIter), weightCol, offsetCol, regParam, | ||
as.double(var.power), as.double(link.power), | ||
stringIndexerOrderType) | ||
new("GeneralizedLinearRegressionModel", jobj = jobj) | ||
|
@@ -182,6 +190,8 @@ setMethod("spark.glm", signature(data = "SparkDataFrame", formula = "formula"), | |
#' \code{poisson}, \code{Gamma}, and \code{tweedie}. | ||
#' @param weightCol the weight column name. If this is not set or \code{NULL}, we treat all instance | ||
#' weights as 1.0. | ||
#' @param offsetCol the offset column name. If this is not set or empty, we treat all instance offsets | ||
#' as 0.0. The feature specified as offset has a constant coefficient of 1.0. | ||
#' @param epsilon positive convergence tolerance of iterations. | ||
#' @param maxit integer giving the maximal number of IRLS iterations. | ||
#' @param var.power the index of the power variance function in the Tweedie family. | ||
|
@@ -207,11 +217,11 @@ setMethod("spark.glm", signature(data = "SparkDataFrame", formula = "formula"), | |
#' @seealso \link{spark.glm} | ||
setMethod("glm", signature(formula = "formula", family = "ANY", data = "SparkDataFrame"), | ||
function(formula, family = gaussian, data, epsilon = 1e-6, maxit = 25, weightCol = NULL, | ||
var.power = 0.0, link.power = 1.0 - var.power, | ||
offsetCol = NULL, var.power = 0.0, link.power = 1.0 - var.power, | ||
stringIndexerOrderType = c("frequencyDesc", "frequencyAsc", | ||
"alphabetDesc", "alphabetAsc")) { | ||
spark.glm(data, formula, family, tol = epsilon, maxIter = maxit, weightCol = weightCol, | ||
var.power = var.power, link.power = link.power, | ||
offsetCol = offsetCol, var.power = var.power, link.power = link.power, | ||
stringIndexerOrderType = stringIndexerOrderType) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid adding a param in the middle - it breaks code passing param by order