spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sethah <...@git.apache.org>
Subject [GitHub] spark pull request #16740: [SPARK-19400][ML] Allow GLM to handle intercept o...
Date Tue, 31 Jan 2017 01:33:33 GMT
Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16740#discussion_r98578921
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/regression/GeneralizedLinearRegressionSuite.scala
---
    @@ -743,6 +743,54 @@ 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")
    +        .setLinkPredictionCol("linkPrediction")
    +      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.")
    --- End diff --
    
    `assert(model.coefficients === new DenseVector(Array.empty[Double]))`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message