Github user rotationsymmetry commented on a diff in the pull request:
https://github.com/apache/spark/pull/8022#discussion_r38005456
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/classification/StreamingLogisticRegressionSuite.scala
---
@@ -184,4 +184,72 @@ class StreamingLogisticRegressionSuite extends
SparkFunSuite with TestSuiteBase
)
val output: Seq[Seq[(Double, Double)]] = runStreams(ssc, numBatches,
numBatches)
}
+
+ test("parameter accuracy with full memory (decayFactor = 1)") {
+
+ val nPoints = 100
+
+ // create model
+ val model = new StreamingLogisticRegressionWithSGD()
+ .setDecayFactor(1)
+ .setInitialWeights(Vectors.dense(0.0))
+ .setStepSize(0.5)
+ .setNumIterations(50)
+
+ // generate sequence of simulated data
+ val numBatches = 20
+ // the first few RDD's are generated under the model A
+ val inputA = (0 until (numBatches - 1)).map { i =>
+ LogisticRegressionSuite.generateLogisticInput(0.0, 0.5, nPoints, 42
* (i + 1))
+ }
+ // the last RDD is generated under the model B
+ val inputB =
+ LogisticRegressionSuite.generateLogisticInput(0.0, 1.5, nPoints, 42
* (numBatches + 1))
+ val input = inputA :+ inputB
+
+ // apply model training to input stream
+ ssc = setupStreams(input, (inputDStream: DStream[LabeledPoint]) => {
+ model.trainOn(inputDStream)
+ inputDStream.count()
+ })
+ runStreams(ssc, numBatches, numBatches)
+
+ // with full memory, the final parameter estimates should be close to
model A
+ assert(model.latestModel().weights(0) ~== 0.5 relTol 0.5)
--- End diff --
In the test "parameter accuracy with full memory (decayFactor = 1)", all
RDD effectively contribute equally to the final estimate. Since the last RDD is
generated with a different model than the previous RDD, the final estimate has
more variability than usual.
In the test "parameter accuracy with no memory (decayFactor = 0)",
effectively all the previous RDD are ignored and the algorithm only has the
samples from the last RDD to work with. Therefore the sample size provided to
the algorithm is small and the estimate could fluctuate quite a bit.
In summary, for a smaller tolerance, we basically need to reduce the
variability of the final estimate. I have increased the number of records in
each RDD in the stream along with small tweak to the parameters. Now we can
pass these tests consistently with 10% tolerance. Will include these update in
my next push to the PR.
---
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]