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

    https://github.com/apache/spark/pull/15435#discussion_r133830867
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala
 ---
    @@ -199,15 +199,57 @@ class LogisticRegressionSuite
         }
       }
     
    -  test("empty probabilityCol") {
    -    val lr = new LogisticRegression().setProbabilityCol("")
    -    val model = lr.fit(smallBinaryDataset)
    -    assert(model.hasSummary)
    -    // Validate that we re-insert a probability column for evaluation
    -    val fieldNames = model.summary.predictions.schema.fieldNames
    -    assert(smallBinaryDataset.schema.fieldNames.toSet.subsetOf(
    -      fieldNames.toSet))
    -    assert(fieldNames.exists(s => s.startsWith("probability_")))
    +  test("empty probabilityCol or predictionCol") {
    +    val lr = new LogisticRegression().setMaxIter(1)
    +    val datasetFieldNames = smallBinaryDataset.schema.fieldNames.toSet
    +    def checkSummarySchema(model: LogisticRegressionModel, columns: 
Seq[String]): Unit = {
    +      val fieldNames = model.summary.predictions.schema.fieldNames
    +      assert(model.hasSummary)
    +      assert(datasetFieldNames.subsetOf(fieldNames.toSet))
    +      columns.foreach { c => assert(fieldNames.exists(_.startsWith(c))) }
    +    }
    +    // check that the summary model adds the appropriate columns
    +    Seq(("binomial", smallBinaryDataset), ("multinomial", 
smallMultinomialDataset)).foreach {
    +      case (family, dataset) =>
    +        lr.setFamily(family)
    +        lr.setProbabilityCol("").setPredictionCol("prediction")
    +        val modelNoProb = lr.fit(smallBinaryDataset)
    +        checkSummarySchema(modelNoProb, Seq("probability_"))
    +
    +        lr.setProbabilityCol("probability").setPredictionCol("")
    +        val modelNoPred = lr.fit(smallBinaryDataset)
    +        checkSummarySchema(modelNoPred, Seq("prediction_"))
    +
    +        lr.setProbabilityCol("").setPredictionCol("")
    +        val modelNoPredNoProb = lr.fit(smallBinaryDataset)
    +        checkSummarySchema(modelNoPredNoProb, Seq("prediction_", 
"probability_"))
    +    }
    +  }
    +
    +  test("check summary types for binary and multiclass") {
    +    val lr = new LogisticRegression()
    +      .setFamily("binomial")
    +
    +    val blorModel = lr.fit(smallBinaryDataset)
    +    
assert(blorModel.summary.isInstanceOf[BinaryLogisticRegressionTrainingSummaryImpl])
    --- End diff --
    
    nit: You can test for the public trait 
BinaryLogisticRegressionTrainingSummary instead of the private implementation 
class.


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