Github user imatiach-msft commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16740#discussion_r99276472
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/regression/GeneralizedLinearRegressionSuite.scala
 ---
    @@ -743,6 +744,48 @@ class GeneralizedLinearRegressionSuite
         }
       }
     
    +  test("generalized linear regression: intercept only") {
    +    /*
    +      R code:
    +      y <- c(17, 19, 23, 29)
    +      w <- c(1, 2, 3, 4)
    +      model1 <- glm(y ~ 1, family = poisson)
    +      model2 <- glm(y ~ 1, family = poisson, weights = w)
    +      as.vector(c(coef(model1), coef(model2)))
    +      [1] 3.091042 3.178054
    +     */
    +
    +    val dataset = Seq(
    +      Instance(17.0, 1.0, Vectors.zeros(0)),
    +      Instance(19.0, 2.0, Vectors.zeros(0)),
    +      Instance(23.0, 3.0, Vectors.zeros(0)),
    +      Instance(29.0, 4.0, Vectors.zeros(0))
    +    ).toDF()
    +
    +    val expected = Seq(3.091, 3.178)
    +
    +    import GeneralizedLinearRegression._
    +
    +    var idx = 0
    +    for (useWeight <- Seq(false, true)) {
    +      val trainer = new GeneralizedLinearRegression().setFamily("poisson")
    +      if (useWeight) trainer.setWeightCol("weight")
    +      val model = trainer.fit(dataset)
    +      val actual = model.intercept
    +      assert(actual ~== expected(idx) absTol 1E-3, "Model mismatch: 
intercept only GLM with " +
    +        s"useWeight = $useWeight.")
    +      assert(model.coefficients === new DenseVector(Array.empty[Double]))
    +
    +      idx += 1
    +    }
    +
    +    // throw exception for empty model
    +    val trainer = new GeneralizedLinearRegression().setFitIntercept(false)
    +    intercept[SparkException] {
    --- End diff --
    
    thank you for adding the test, could you also please wrap it in withClue to 
verify the message contents, eg:
    withClue("Specified model is empty with neither intercept nor feature") {
    intercept[SparkException] { 
    trainer.fit(dataset) 
    } 
    }


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