Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3833#discussion_r23824003
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
 ---
    @@ -228,7 +274,34 @@ abstract class GeneralizedLinearAlgorithm[M <: 
GeneralizedLinearModel]
          * is the coefficient in the original space, and v_i is the variance 
of the column i.
          */
         if (useFeatureScaling) {
    -      weights = scaler.transform(weights)
    +      if (numOfLinearPredictor == 1) {
    +        weights = scaler.transform(weights)
    +      } else {
    +        /**
    +         * For `numOfLinearPredictor > 1`, we have to transform the 
weights back to the original
    +         * scale for each set of linear predictor. Note that the 
intercepts have to be explicitly
    +         * excluded when `addIntercept == true` since the intercepts are 
part of weights now.
    +         */
    +        var i = 0
    +        val weightsArray = weights.toArray
    +        while (i < numOfLinearPredictor) {
    +          val start = i * (weights.size / numOfLinearPredictor)
    +          val end = (i + 1) * (weights.size / numOfLinearPredictor) - { if 
(addIntercept) 1 else 0 }
    +
    +          val partialWeightsArray = scaler.transform(
    +            Vectors.dense(weightsArray.slice(start, end))).toArray
    +
    +          var j = start
    +          var k = 0
    +          while (j < end) {
    +            weightsArray(j) = partialWeightsArray(k)
    --- End diff --
    
    `System.arraycopy`


---
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]

Reply via email to