Github user actuaryzhang commented on a diff in the pull request:
https://github.com/apache/spark/pull/16699#discussion_r124399685
--- 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 --
I would suggest we leave `WeightedLeastSquares` as is, since it is a
general purpose optimization tool and offset is more specific to GLM. I have
not seen a weighted least squares implementation that supports offset.
We discussed something relevant above
[here](https://github.com/apache/spark/pull/16699/files/d44974cfe50092bb639a31aa7aa9b16eb1d21fae#diff-6759d92c079f0957bfa814e339e10e7eR301
). I originally defined `val instances: RDD[OffsetInstance]` outside the
`ifelse` and then convert it to `RDD[Instance]` for the Gaussian identity link
case. But this will incur one extra map. There was some concern that this could
be expensive. However, if this extra conversion is not a big deal, I can revert
it back to that which is basically the implementation of the `OffsetInstance`
interface for `WeightedLeastSquares`.
---
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]