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

    https://github.com/apache/spark/pull/10274#discussion_r49667844
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/optim/WeightedLeastSquares.scala ---
    @@ -94,8 +110,7 @@ private[ml] class WeightedLeastSquares(
           if (standardizeFeatures) {
             lambda *= aVar(j - 2)
           }
    -      if (standardizeLabel) {
    -        // TODO: handle the case when bStd = 0
    +      if (standardizeLabel && bStd != 0) {
    --- End diff --
    
    Here is the exercise,
    
    ```scala
      test("WLS against lm") {
        /*
           R code:
    
           df <- as.data.frame(cbind(A, b))
           for (formula in c(b ~ . -1, b ~ .)) {
             model <- lm(formula, data=df, weights=w)
             print(as.vector(coef(model)))
           }
    
           [1] -3.727121  3.009983
           [1] 18.08  6.08 -0.60
         */
    
        val expected = Seq(
          Vectors.dense(0.0, -3.727121, 3.009983),
          Vectors.dense(18.08, 6.08, -0.60))
    
        var idx = 0
        for (fitIntercept <- Seq(false, true)) {
          for (standardization <- Seq(false, true)) {
            val wls = new WeightedLeastSquares(
              fitIntercept, regParam = 0.0, standardizeFeatures = 
standardization,
              standardizeLabel = standardization).fit(instances)
            val actual = Vectors.dense(wls.intercept, wls.coefficients(0), 
wls.coefficients(1))
            assert(actual ~== expected(idx) absTol 1e-4)
          }
          idx += 1
        }
      }
    ```



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

Reply via email to