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 #15435: [SPARK-17139][ML] Add model summary for Multinomi...
Date Wed, 04 Jan 2017 19:04:20 GMT
Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15435#discussion_r94640068
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala
---
    @@ -1762,51 +1781,101 @@ 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()
    +    val blor = 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())
    +    val blorModel = blor.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())
    +
    +    val mlor = new LogisticRegression()
    +      .setMaxIter(10)
    +      .setRegParam(1.0)
    +      .setFamily("multinomial")
    +    val mlorModel = blor.fit(smallMultinomialDataset)
    +    val mlorSummary = mlorModel.summary
    +
    +    val mlorSameSummary = mlorModel.evaluate(smallMultinomialDataset)
    +      .asInstanceOf[MultinomialLogisticRegressionSummary]
    +
    +    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.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)
    --- End diff --
    
    add `.setFamily("binomial")`


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