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

    https://github.com/apache/spark/pull/16630#discussion_r101822942
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/regression/GeneralizedLinearRegressionSuite.scala
 ---
    @@ -1104,6 +1103,83 @@ class GeneralizedLinearRegressionSuite
           .fit(datasetGaussianIdentity.as[LabeledPoint])
       }
     
    +
    +  test("glm summary: feature name") {
    +    // dataset1 with no attribute
    +    val dataset1 = Seq(
    +      Instance(2.0, 1.0, Vectors.dense(0.0, 5.0)),
    +      Instance(8.0, 2.0, Vectors.dense(1.0, 7.0)),
    +      Instance(3.0, 3.0, Vectors.dense(2.0, 11.0)),
    +      Instance(9.0, 4.0, Vectors.dense(3.0, 13.0)),
    +      Instance(2.0, 5.0, Vectors.dense(2.0, 3.0))
    +    ).toDF()
    +
    +    // dataset2 with attribute
    +    val datasetTmp = Seq(
    +      (2.0, 1.0, 0.0, 5.0),
    +      (8.0, 2.0, 1.0, 7.0),
    +      (3.0, 3.0, 2.0, 11.0),
    +      (9.0, 4.0, 3.0, 13.0),
    +      (2.0, 5.0, 2.0, 3.0)
    +    ).toDF("y", "w", "x1", "x2")
    +    val formula = new RFormula().setFormula("y ~ x1 + x2")
    +    val dataset2 = formula.fit(datasetTmp).transform(datasetTmp)
    +
    +    val expectedFeature = Seq(Array("features_0", "features_1"), 
Array("x1", "x2"))
    +
    +    var idx = 0
    +    for (dataset <- Seq(dataset1, dataset2)) {
    +      val model = new GeneralizedLinearRegression().fit(dataset)
    +      model.summary.featureNames.zip(expectedFeature(idx))
    +        .foreach{ x => assert(x._1 === x._2) }
    +      idx += 1
    +    }
    +  }
    +
    +  test("glm summary: summaryTable") {
    +    val dataset = Seq(
    +      Instance(2.0, 1.0, Vectors.dense(0.0, 5.0)),
    +      Instance(8.0, 2.0, Vectors.dense(1.0, 7.0)),
    +      Instance(3.0, 3.0, Vectors.dense(2.0, 11.0)),
    +      Instance(9.0, 4.0, Vectors.dense(3.0, 13.0)),
    +      Instance(2.0, 5.0, Vectors.dense(2.0, 3.0))
    +    ).toDF()
    +
    +    val expectedFeature = Seq(Array("features_0", "features_1"),
    +      Array("(Intercept)", "features_0", "features_1"))
    +    val expectedEstimate = Seq(Vectors.dense(0.2884, 0.538),
    --- End diff --
    
    Thanks. Added in R code. 


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