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

    https://github.com/apache/spark/pull/1897#discussion_r16099170
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/classification/LogisticRegressionSuite.scala
 ---
    @@ -185,6 +185,58 @@ class LogisticRegressionSuite extends FunSuite with 
LocalSparkContext with Match
         // Test prediction on Array.
         validatePrediction(validationData.map(row => 
model.predict(row.features)), validationData)
       }
    +
    +  test("numerical stability of scaling features using logistic regression 
with LBFGS") {
    +    /**
    +     * If we rescale the features, the condition number will be changed so 
the convergence rate
    +     * and the solution will not equal to the original solution multiple 
by the scaling factor
    +     * which it should be.
    +     *
    +     * However, since in the LogisticRegressionWithLBFGS, we standardize 
the training dataset first,
    +     * no matter how we multiple a scaling factor into the dataset, the 
convergence rate should be
    +     * the same, and the solution should equal to the original solution 
multiple by the scaling
    +     * factor.
    +     */
    +
    +    val nPoints = 10000
    +    val A = 2.0
    +    val B = -1.5
    +
    +    val testData = LogisticRegressionSuite.generateLogisticInput(A, B, 
nPoints, 42)
    +
    +    val initialWeights = Vectors.dense(0.0)
    +
    +    val testRDD1 = sc.parallelize(testData, 2)
    +
    +    val testRDD2 = sc.parallelize(
    +      testData.map(x => LabeledPoint(x.label, 
Vectors.fromBreeze(x.features.toBreeze * 1.0E3))), 2)
    +
    +    val testRDD3 = sc.parallelize(
    +      testData.map(x => LabeledPoint(x.label, 
Vectors.fromBreeze(x.features.toBreeze * 1.0E6))), 2)
    +
    +    testRDD1.cache()
    +    testRDD2.cache()
    +    testRDD3.cache()
    +
    +    val lrA = new LogisticRegressionWithLBFGS().setIntercept(true)
    +    val lrB = new 
LogisticRegressionWithLBFGS().setIntercept(true).setFeatureScaling(false)
    +
    +    val modelA1 = lrA.run(testRDD1, initialWeights)
    +    val modelA2 = lrA.run(testRDD2, initialWeights)
    +    val modelA3 = lrA.run(testRDD3, initialWeights)
    +
    +    val modelB1 = lrB.run(testRDD1, initialWeights)
    +    val modelB2 = lrB.run(testRDD2, initialWeights)
    +    val modelB3 = lrB.run(testRDD3, initialWeights)
    +
    +    // Test the weights
    +    assert(modelA1.weights(0) ~== modelA2.weights(0) * 1.0E3 absTol 0.01)
    +    assert(modelA1.weights(0) ~== modelA3.weights(0) * 1.0E6 absTol 0.01)
    +
    +    assert(modelB1.weights(0) !~== modelB2.weights(0) * 1.0E3 absTol 0.1)
    --- End diff --
    
    need a comment about the purpose of the tests here


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