Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/2037#discussion_r16432724
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionSuite.scala
---
@@ -132,4 +116,33 @@ class StreamingLinearRegressionSuite extends FunSuite
with LocalSparkContext {
}
+ // Test predictions on a stream
+ test("predictions") {
+
+ // create model initialized with true weights
+ val model = new StreamingLinearRegressionWithSGD()
+ .setInitialWeights(Vectors.dense(10.0, 10.0))
+ .setStepSize(0.1)
+ .setNumIterations(25)
+
+ // generate sequence of simulated data for testing
+ val numBatches = 10
+ val nPoints = 100
+ val testInput = (0 until numBatches).map { i =>
+ LinearDataGenerator.generateLinearInput(0.0, Array(10.0, 10.0),
nPoints, 42 * (i + 1))
+ }
+
+ // apply model predictions to test stream
+ val ssc = setupStreams(testInput, (inputDStream:
DStream[LabeledPoint]) => {
+ model.predictOnValues(inputDStream.map(x => (x.label, x.features)))
+ })
+ // collect the output as (true, estimated) tuples
+ val output: Seq[Seq[(Double, Double)]] = runStreams(ssc, numBatches,
numBatches)
+
+ // compute the mean absolute error and check that it's always less
than 0.1
+ val errors = output.map(batch => batch.map(p => math.abs(p._1 -
p._2)).sum / nPoints)
+ assert(errors.forall(x => x <= 0.1))
+
+ }
+
--- End diff --
nit: extra line
---
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]