Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/16699#discussion_r124261785
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala
---
@@ -339,15 +364,16 @@ class GeneralizedLinearRegression @Since("2.0.0")
(@Since("2.0.0") override val
"GeneralizedLinearRegression was given data with 0 features, and
with Param fitIntercept " +
"set to false. To fit a model with 0 features, fitIntercept must
be set to true." )
- val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0)
else col($(weightCol))
- val instances: RDD[Instance] =
- dataset.select(col($(labelCol)), w, col($(featuresCol))).rdd.map {
- case Row(label: Double, weight: Double, features: Vector) =>
- Instance(label, weight, features)
- }
+ val w = if (!isSetWeightCol(this)) lit(1.0) else col($(weightCol))
+ val offset = if (!isSetOffsetCol(this)) lit(0.0) else
col($(offsetCol)).cast(DoubleType)
val model = if (familyAndLink.family == Gaussian && familyAndLink.link
== Identity) {
// TODO: Make standardizeFeatures and standardizeLabel configurable.
+ val instances: RDD[Instance] =
+ dataset.select(col($(labelCol)), w, offset,
col($(featuresCol))).rdd.map {
+ case Row(label: Double, weight: Double, offset: Double,
features: Vector) =>
+ Instance(label - offset, weight, features)
+ }
val optimizer = new WeightedLeastSquares($(fitIntercept),
$(regParam), elasticNetParam = 0.0,
standardizeFeatures = true, standardizeLabel = true)
val wlsModel = optimizer.fit(instances)
--- End diff --
What do you think of adding a new interface ```fit(instances:
RDD[OffsetInstance])``` for ```WeightedLeastSquares```? Then we can remove some
redundant code.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]