Github user yanboliang commented on a diff in the pull request: https://github.com/apache/spark/pull/16699#discussion_r124281406 --- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala --- @@ -961,14 +1007,30 @@ class GeneralizedLinearRegressionModel private[ml] ( } override protected def transformImpl(dataset: Dataset[_]): DataFrame = { - val predictUDF = udf { (features: Vector) => predict(features) } - val predictLinkUDF = udf { (features: Vector) => predictLink(features) } + val predictUDF = udf { (features: Vector, offset: Double) => predict(features, offset) } + val predictLinkUDF = udf { (features: Vector, offset: Double) => predictLink(features, offset) } + /* + Offset is only validated when it's specified in the model and available in prediction data set. + When offset is specified but missing in the prediction data set, we default it to zero. + */ + val offset = { + if (!isSetOffsetCol(this)) { + lit(0.0) + } else { + if (dataset.schema.fieldNames.contains($(offsetCol))) { + SchemaUtils.checkNumericType(dataset.schema, $(offsetCol)) + col($(offsetCol)).cast(DoubleType) + } else { + lit(0.0) + } + } + } --- End diff -- Can we simplify it as following? ``` val offset = if (!isSetOffsetCol(this)) lit(0.0) else col($(offsetCol)).cast(DoubleType) ``` Here it's not necessary to run ```checkNumericType```, since it has been check in ```validateAndTransformSchema```.
--- 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