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

    https://github.com/apache/spark/pull/15435#discussion_r106727119
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala
 ---
    @@ -1786,51 +1793,98 @@ class LogisticRegressionSuite
       }
     
       test("evaluate on test set") {
    -    // TODO: add for multiclass when model summary becomes available
         // Evaluate on test set should be same as that of the transformed 
training data.
         val lr = new LogisticRegression()
           .setMaxIter(10)
           .setRegParam(1.0)
           .setThreshold(0.6)
    -    val model = lr.fit(smallBinaryDataset)
    -    val summary = 
model.summary.asInstanceOf[BinaryLogisticRegressionSummary]
    -
    -    val sameSummary =
    -      
model.evaluate(smallBinaryDataset).asInstanceOf[BinaryLogisticRegressionSummary]
    -    assert(summary.areaUnderROC === sameSummary.areaUnderROC)
    -    assert(summary.roc.collect() === sameSummary.roc.collect())
    -    assert(summary.pr.collect === sameSummary.pr.collect())
    +      .setFamily("binomial")
    +    val blorModel = lr.fit(smallBinaryDataset)
    +    val blorSummary = blorModel.binarySummary
    +
    +    val sameBlorSummary =
    +      
blorModel.evaluate(smallBinaryDataset).asInstanceOf[BinaryLogisticRegressionSummary]
    +    assert(blorSummary.areaUnderROC === sameBlorSummary.areaUnderROC)
    +    assert(blorSummary.roc.collect() === sameBlorSummary.roc.collect())
    +    assert(blorSummary.pr.collect === sameBlorSummary.pr.collect())
         assert(
    -      summary.fMeasureByThreshold.collect() === 
sameSummary.fMeasureByThreshold.collect())
    -    assert(summary.recallByThreshold.collect() === 
sameSummary.recallByThreshold.collect())
    +      blorSummary.fMeasureByThreshold.collect() === 
sameBlorSummary.fMeasureByThreshold.collect())
         assert(
    -      summary.precisionByThreshold.collect() === 
sameSummary.precisionByThreshold.collect())
    +      blorSummary.recallByThreshold.collect() === 
sameBlorSummary.recallByThreshold.collect())
    +    assert(
    +      blorSummary.precisionByThreshold.collect()
    +        === sameBlorSummary.precisionByThreshold.collect())
    +
    +    lr.setFamily("multinomial")
    +    val mlorModel = lr.fit(smallMultinomialDataset)
    +    val mlorSummary = mlorModel.summary
    +
    +    val mlorSameSummary = mlorModel.evaluate(smallMultinomialDataset)
    +
    +    assert(mlorSummary.truePositiveRateByLabel === 
mlorSameSummary.truePositiveRateByLabel)
    +    assert(mlorSummary.falsePositiveRateByLabel === 
mlorSameSummary.falsePositiveRateByLabel)
    +    assert(mlorSummary.precisionByLabel === 
mlorSameSummary.precisionByLabel)
    +    assert(mlorSummary.recallByLabel === mlorSameSummary.recallByLabel)
    +    assert(mlorSummary.fMeasureByLabel === mlorSameSummary.fMeasureByLabel)
    +    assert(mlorSummary.accuracy === mlorSameSummary.accuracy)
    +    assert(mlorSummary.weightedTruePositiveRate === 
mlorSameSummary.weightedTruePositiveRate)
    +    assert(mlorSummary.weightedFalsePositiveRate === 
mlorSameSummary.weightedFalsePositiveRate)
    +    assert(mlorSummary.weightedPrecision === 
mlorSameSummary.weightedPrecision)
    +    assert(mlorSummary.weightedRecall === mlorSameSummary.weightedRecall)
    +    assert(mlorSummary.weightedFMeasure === 
mlorSameSummary.weightedFMeasure)
       }
     
       test("evaluate with labels that are not doubles") {
         // Evaluate a test set with Label that is a numeric type other than 
Double
    -    val lr = new LogisticRegression()
    +    val blor = new LogisticRegression()
           .setMaxIter(1)
           .setRegParam(1.0)
    -    val model = lr.fit(smallBinaryDataset)
    -    val summary = 
model.evaluate(smallBinaryDataset).asInstanceOf[BinaryLogisticRegressionSummary]
    +    val blorModel = blor.fit(smallBinaryDataset)
    +    val blorSummary = blorModel.evaluate(smallBinaryDataset)
    +      .asInstanceOf[BinaryLogisticRegressionSummary]
    +
    +    val blorLongLabelData = 
smallBinaryDataset.select(col(blorModel.getLabelCol).cast(LongType),
    +      col(blorModel.getFeaturesCol))
    +    val blorLongSummary = blorModel.evaluate(blorLongLabelData)
    +      .asInstanceOf[BinaryLogisticRegressionSummary]
    --- End diff --
    
    This is quite annoying. I wonder if we should add a `asBinary` method to 
`LogisticRegressionSummary` that casts it or throws an error to make it easier. 
Probably to do in a separate PR anyway.


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