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

    https://github.com/apache/spark/pull/5967#discussion_r29956327
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala
 ---
    @@ -135,4 +164,302 @@ class LogisticRegressionSuite extends FunSuite with 
MLlibTestSparkContext {
             assert(pred == predFromProb)
         }
       }
    +
    +  test("MultiClassSummarizer") {
    +    val summarizer1 = (new MultiClassSummarizer)
    +      .add(0.0).add(3.0).add(4.0).add(3.0).add(6.0)
    +    assert(summarizer1.histogram.zip(Array[Long](1, 0, 0, 2, 1, 0, 
1)).forall(x => x._1 === x._2))
    +    assert(summarizer1.countInvalid === 0)
    +    assert(summarizer1.numClasses === 7)
    +
    +    val summarizer2 = (new MultiClassSummarizer)
    +      .add(1.0).add(5.0).add(3.0).add(0.0).add(4.0).add(1.0)
    +    assert(summarizer2.histogram.zip(Array[Long](1, 2, 0, 1, 1, 
1)).forall(x => x._1 === x._2))
    +    assert(summarizer2.countInvalid === 0)
    +    assert(summarizer2.numClasses === 6)
    +
    +    val summarizer3 = (new MultiClassSummarizer)
    +      
.add(0.0).add(1.3).add(5.2).add(2.5).add(2.0).add(4.0).add(4.0).add(4.0).add(1.0)
    +    assert(summarizer3.histogram.zip(Array[Long](1, 1, 1, 0, 3)).forall(x 
=> x._1 === x._2))
    +    assert(summarizer3.countInvalid === 3)
    +    assert(summarizer3.numClasses === 5)
    +
    +    val summarizer4 = (new MultiClassSummarizer)
    +      .add(3.1).add(4.3).add(2.0).add(1.0).add(3.0)
    +    assert(summarizer4.histogram.zip(Array[Long](0, 1, 1, 1)).forall(x => 
x._1 === x._2))
    +    assert(summarizer4.countInvalid === 2)
    +    assert(summarizer4.numClasses === 4)
    +
    +    // small map merges large one
    +    val summarizerA = summarizer1.merge(summarizer2)
    +    assert(summarizerA.hashCode() === summarizer2.hashCode())
    +    assert(summarizerA.histogram.zip(Array[Long](2, 2, 0, 3, 2, 1, 
1)).forall(x => x._1 === x._2))
    +    assert(summarizerA.countInvalid === 0)
    +    assert(summarizerA.numClasses === 7)
    +
    +    // large map merges small one
    +    val summarizerB = summarizer3.merge(summarizer4)
    +    assert(summarizerB.hashCode() === summarizer3.hashCode())
    +    assert(summarizerB.histogram.zip(Array[Long](1, 2, 2, 1, 3)).forall(x 
=> x._1 === x._2))
    +    assert(summarizerB.countInvalid === 5)
    +    assert(summarizerB.numClasses === 5)
    +  }
    +
    +  test("binary logistic regression with intercept without regularization") 
{
    +    val trainer = (new LogisticRegression).setFitIntercept(true)
    +    val model = trainer.fit(binaryDataset)
    +
    +    /**
    +     * Using the following R code to load the data and train the model 
using glmnet package.
    +     *
    +     * > library("glmnet")
    +     * > data <- read.csv("path", header=FALSE)
    +     * > label = factor(data$V1)
    +     * > features = as.matrix(data.frame(data$V2, data$V3, data$V4, 
data$V5))
    +     * > weights = coef(glmnet(features,label, family="binomial", alpha = 
0, lambda = 0))
    +     * > weights
    --- End diff --
    
    This is great!


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