Github user freeman-lab commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1361#discussion_r15628354
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionSuite.scala
 ---
    @@ -0,0 +1,127 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.mllib.regression
    +
    +import java.io.File
    +
    +import com.google.common.io.Files
    +import org.apache.commons.io.FileUtils
    +import org.scalatest.FunSuite
    +import org.apache.spark.SparkConf
    +import org.apache.spark.streaming.{Milliseconds, Seconds, StreamingContext}
    +import org.apache.spark.mllib.util.{MLStreamingUtils, LinearDataGenerator, 
LocalSparkContext}
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +class StreamingLinearRegressionSuite extends FunSuite {
    +
    +  // Assert that two values are equal within tolerance epsilon
    +  def assertEqual(v1: Double, v2: Double, epsilon: Double) {
    +    def errorMessage = v1.toString + " did not equal " + v2.toString
    +    assert(math.abs(v1-v2) <= epsilon, errorMessage)
    +  }
    +
    +  // Assert that model predictions are correct
    +  def validatePrediction(predictions: Seq[Double], input: 
Seq[LabeledPoint]) {
    +    val numOffPredictions = predictions.zip(input).count { case 
(prediction, expected) =>
    +      // A prediction is off if the prediction is more than 0.5 away from 
expected value.
    +      math.abs(prediction - expected.label) > 0.5
    +    }
    +    // At least 80% of the predictions should be on.
    +    assert(numOffPredictions < input.length / 5)
    +  }
    +
    +  // Test if we can accurately learn Y = 10*X1 + 10*X2 on streaming data
    +  test("streaming linear regression parameter accuracy") {
    +
    +    val conf = new SparkConf().setMaster("local").setAppName("streaming 
test")
    +    val testDir = Files.createTempDir()
    +    val numBatches = 10
    +    val ssc = new StreamingContext(conf, Seconds(1))
    +    val data = MLStreamingUtils.loadLabeledPointsFromText(ssc, 
testDir.toString)
    +    val model = StreamingLinearRegressionWithSGD.start(numFeatures=2, 
numIterations=50)
    +
    +    model.trainOn(data)
    +
    +    ssc.start()
    +
    +    // write data to a file stream
    +    Thread.sleep(5000)
    --- End diff --
    
    MIght not be =) I added it because I saw it in the streaming test suite for 
file writing, but without it both tests still pass fine.


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

Reply via email to