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

    https://github.com/apache/spark/pull/17715#discussion_r112736608
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala
 ---
    @@ -1149,6 +1300,49 @@ class LogisticRegressionSuite
         assert(model2.interceptVector.toArray.sum ~== 0.0 absTol eps)
       }
     
    +  test("multinomial logistic regression with intercept without 
regularization with bound") {
    +    val lowerBoundOfCoefficients = Matrices.dense(3, 4, 
Array.fill(12)(1.0))
    +    val lowerBoundOfIntercept = Vectors.dense(Array.fill(3)(1.0))
    +
    +    val trainer1 = new LogisticRegression()
    +      .setLowerBoundOfCoefficients(lowerBoundOfCoefficients)
    +      .setLowerBoundOfIntercept(lowerBoundOfIntercept)
    +      .setFitIntercept(true)
    +      .setStandardization(true)
    +      .setWeightCol("weight")
    +    val trainer2 = new LogisticRegression()
    +      .setLowerBoundOfCoefficients(lowerBoundOfCoefficients)
    +      .setLowerBoundOfIntercept(lowerBoundOfIntercept)
    +      .setFitIntercept(true)
    +      .setStandardization(false)
    +      .setWeightCol("weight")
    +
    +    val model1 = trainer1.fit(multinomialDataset)
    +    val model2 = trainer2.fit(multinomialDataset)
    +
    +    // The solution is generated by 
https://github.com/yanboliang/bound-optimization.
    +    val coefficientsExpected = new DenseMatrix(3, 4, Array(
    +      2.52076464, 2.73596057, 1.87984904, 2.73264492,
    +      1.93302281, 3.71363303, 1.50681746, 1.93398782,
    +      2.37839917, 1.93601818, 1.81924758, 2.45191255), isTransposed = true)
    +    val interceptsExpected = Vectors.dense(1.00010477, 3.44237083, 
4.86740286)
    +
    +    model1.coefficientMatrix.colIter.zip(coefficientsExpected.colIter)
    +      .foreach { case (col1: Vector, col2: Vector) =>
    +        (col1.asBreeze - col2.asBreeze).toArray.toSeq.sliding(2).foreach {
    +          case Seq(v1, v2) => assert(v1 ~== v2 absTol 1E-3)
    +        }
    +      }
    --- End diff --
    
    When reg == 0, multinomial logistic regression has multiple solutions and 
we centralize the coefficients to get identical result for non-bound 
regression, but we didn't do this for bound constrained regression, since it 
may cross the bound if we centralize them. So here we check whether 
```coefficients1``` equals to ```coefficientsExpected + constant value``` for 
each column. 


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