You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by freeman-lab <gi...@git.apache.org> on 2014/08/19 19:08:58 UTC

[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

GitHub user freeman-lab opened a pull request:

    https://github.com/apache/spark/pull/2037

    [SPARK-3128][MLLIB] Use streaming test suite for StreamingLR

    Refactored tests for streaming linear regression to use existing  streaming test utilities. Summary of changes:
    - Made ``mllib`` depend on tests from ``streaming``
    - Rewrote prediction and convergence tests to use ``setupStreams`` and ``runStreams``
    - Added new test for the accuracy of predictions generated by ``predictOnValue``
    
    These tests should run faster, be easier to extend/maintain, and provide a reference for new tests.
    
    @mengxr @tdas

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/freeman-lab/spark streamingLR-predict-tests

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/2037.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2037
    
----
commit 32c43c2928868505a3af3a79db8e25a494a7c09a
Author: freeman <th...@gmail.com>
Date:   2014-08-19T02:25:38Z

    Added test for prediction
    
    - Test predictOnValues for accuracy on a test stream

commit 50eb0bfcf59b8fc3f8ab7b441eb3cbbf46299e1f
Author: freeman <th...@gmail.com>
Date:   2014-08-19T16:53:46Z

    Refactored tests to use streaming test tools
    
    - Made mllib depend on tests from streaming
    - Rewrote all streamingLR tests to use the setupStreams & runStreams
    functions

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52666736
  
    Jenkins, test this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by freeman-lab <gi...@git.apache.org>.
Github user freeman-lab commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52674848
  
    Jenkins, test this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52667035
  
      [QA tests have started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18852/consoleFull) for   PR 2037 at commit [`50eb0bf`](https://github.com/apache/spark/commit/50eb0bfcf59b8fc3f8ab7b441eb3cbbf46299e1f).
     * This patch merges cleanly.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by tdas <gi...@git.apache.org>.
Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2037#discussion_r16432740
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionSuite.scala ---
    @@ -132,4 +116,33 @@ class StreamingLinearRegressionSuite extends FunSuite with LocalSparkContext {
     
    --- 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52674966
  
      [QA tests have started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18858/consoleFull) for   PR 2037 at commit [`e851ca7`](https://github.com/apache/spark/commit/e851ca745883d19bfd7b8d5479ab2124a9bd4278).
     * This patch merges cleanly.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by tdas <gi...@git.apache.org>.
Github user tdas commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52676007
  
    LGTM, if tests pass. Small nits, which can be ignored if there is nothing else to be changed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by tdas <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by freeman-lab <gi...@git.apache.org>.
Github user freeman-lab commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52683846
  
    @mengxr @tdas thanks for reviewing!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by tdas <gi...@git.apache.org>.
Github user tdas commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52694113
  
    Thanks a lot @freeman-lab 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52716695
  
    @tdas It seems that this creates a folder called `checkpoint` under `mllib` and breaks Jenkins build.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52683420
  
      [QA tests have finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18860/consoleFull) for   PR 2037 at commit [`e851ca7`](https://github.com/apache/spark/commit/e851ca745883d19bfd7b8d5479ab2124a9bd4278).
     * This patch **passes** unit tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2037#discussion_r16428793
  
    --- Diff: streaming/src/test/scala/org/apache/spark/streaming/TestSuiteBase.scala ---
    @@ -242,7 +242,7 @@ trait TestSuiteBase extends FunSuite with BeforeAndAfter with Logging {
         logInfo("numBatches = " + numBatches + ", numExpectedOutput = " + numExpectedOutput)
     
         // Get the output buffer
    -    val outputStream = ssc.graph.getOutputStreams.head.asInstanceOf[TestOutputStreamWithPartitions[V]]
    +    val outputStream = ssc.graph.getOutputStreams.filter(_.isInstanceOf[TestOutputStreamWithPartitions[_]]).head.asInstanceOf[TestOutputStreamWithPartitions[V]]
    --- End diff --
    
    This line is over 100 characters.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52683359
  
      [QA tests have finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18858/consoleFull) for   PR 2037 at commit [`e851ca7`](https://github.com/apache/spark/commit/e851ca745883d19bfd7b8d5479ab2124a9bd4278).
     * This patch **passes** unit tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by tdas <gi...@git.apache.org>.
Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2037#discussion_r16432719
  
    --- 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52673550
  
      [QA tests have finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18852/consoleFull) for   PR 2037 at commit [`50eb0bf`](https://github.com/apache/spark/commit/50eb0bfcf59b8fc3f8ab7b441eb3cbbf46299e1f).
     * This patch **fails** unit tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/2037#issuecomment-52675684
  
      [QA tests have started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18860/consoleFull) for   PR 2037 at commit [`e851ca7`](https://github.com/apache/spark/commit/e851ca745883d19bfd7b8d5479ab2124a9bd4278).
     * This patch merges cleanly.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/2037


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-3128][MLLIB] Use streaming test suite f...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2037#discussion_r16428916
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionSuite.scala ---
    @@ -132,4 +116,34 @@ 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)).reduce(_+_) / nPoints.toDouble)
    --- End diff --
    
    `.reduce(_+_)` -> `sum`
    
    Then it could be fit into one line:
    ~~~
    val errors = output.map(batch => batch.map(p => math.abs(p._1 - p._2)).sum / nPoints)
    ~~~
    
    sum returns Double so we don't need to call `toDouble` explicitly.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org