GitHub PullRequestReviewCommentEvent at 2014-07-30 03:49:55
Repository: spark
Actor: mengxr
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/15565590","id":15565590,"diff_hunk":"@@ -0,0 +1,104 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.mllib.regression\n+\n+import org.apache.spark.mllib.linalg.Vectors\n+import org.apache.spark.annotation.Experimental\n+\n+/**\n+ * Train or predict a linear regression model on streaming data. Training uses\n+ * Stochastic Gradient Descent to update the model based on each new batch of\n+ * incoming data from a DStream (see LinearRegressionWithSGD for model equation)\n+ *\n+ * Each batch of data is assumed to be an RDD of LabeledPoints.\n+ * The number of data points per batch can vary, but the number\n+ * of features must be constant.\n+ */\n+@Experimental\n+class StreamingLinearRegressionWithSGD private (\n+    private var stepSize: Double,\n+    private var numIterations: Int,\n+    private var miniBatchFraction: Double,\n+    private var numFeatures: Int)\n+  extends StreamingRegression[LinearRegressionModel, LinearRegressionWithSGD] with Serializable {\n+\n+  val algorithm = new LinearRegressionWithSGD(stepSize, numIterations, miniBatchFraction)\n+\n+  var model = algorithm.createModel(Vectors.dense(new Array[Double](numFeatures)), 0.0)\n+\n+}\n+\n+/**\n+ * Top-level methods for calling StreamingLinearRegressionWithSGD.\n+ */\n+@Experimental\n+object StreamingLinearRegressionWithSGD {\n+\n+  /**\n+   * Start a streaming Linear Regression model by setting optimization parameters.\n+   *\n+   * @param numIterations Number of iterations of gradient descent to run.\n+   * @param stepSize Step size to be used for each iteration of gradient descent.\n+   * @param miniBatchFraction Fraction of data to be used per iteration.\n+   * @param numFeatures Number of features per record, must be constant for all batches of data.\n+   */\n+  def start(","path":"mllib/src/main/scala/org/apache/spark/mllib/regression/StreamingLinearRegression.scala","position":60,"original_position":60,"commit_id":"a2a63ad827994c86d517b7227c064420b80117c1","original_commit_id":"a2a63ad827994c86d517b7227c064420b80117c1","user":{"login":"mengxr","id":829644,"avatar_url":"https://avatars.githubusercontent.com/u/829644?v=1","gravatar_id":"0e16fce91950d1b5a312649751ff1b14","url":"https://api.github.com/users/mengxr","html_url":"https://github.com/mengxr","followers_url":"https://api.github.com/users/mengxr/followers","following_url":"https://api.github.com/users/mengxr/following{/other_user}","gists_url":"https://api.github.com/users/mengxr/gists{/gist_id}","starred_url":"https://api.github.com/users/mengxr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mengxr/subscriptions","organizations_url":"https://api.github.com/users/mengxr/orgs","repos_url":"https://api.github.com/users/mengxr/repos","events_url":"https://api.github.com/users/mengxr/events{/privacy}","received_events_url":"https://api.github.com/users/mengxr/received_events","type":"User","site_admin":false},"body":"Instead of having static methods, we can define setter methods inside the class and provide a default constructor with no arguments. Then user can use a builder pattern to construct the streaming update algorithm:\r\n\r\n~~~\r\nnew StreamingLinearRegressionWithSGD()\r\n  .setStepSize(0.5)\r\n  .setNumIterations(10)\r\n  .setInitialWeights(Vectors.dense(...))\r\n  .trainOn(DStream)\r\n~~~","created_at":"2014-07-30T03:49:55Z","updated_at":"2014-07-30T03:49:55Z","html_url":"https://github.com/apache/spark/pull/1361#discussion_r15565590","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/1361","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/15565590"},"html":{"href":"https://github.com/apache/spark/pull/1361#discussion_r15565590"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/1361"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/1361","id":18242360,"html_url":"https://github.com/apache/spark/pull/1361","diff_url":"https://github.com/apache/spark/pull/1361.diff","patch_url":"https://github.com/apache/spark/pull/1361.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/1361","number":1361,"state":"open","title":"Streaming mllib [SPARK-2438][MLLIB]","user":{"login":"freeman-lab","id":3387500,"avatar_url":"https://avatars.githubusercontent.com/u/3387500?v=1","gravatar_id":"f19e21b5a19032902638f1fb2c4ee49f","url":"https://api.github.com/users/freeman-lab","html_url":"https://github.com/freeman-lab","followers_url":"https://api.github.com/users/freeman-lab/followers","following_url":"https://api.github.com/users/freeman-lab/following{/other_user}","gists_url":"https://api.github.com/users/freeman-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/freeman-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeman-lab/subscriptions","organizations_url":"https://api.github.com/users/freeman-lab/orgs","repos_url":"https://api.github.com/users/freeman-lab/repos","events_url":"https://api.github.com/users/freeman-lab/events{/privacy}","received_events_url":"https://api.github.com/users/freeman-lab/received_events","type":"User","site_admin":false},"body":"This PR implements a streaming linear regression analysis, in which a linear regression model is trained online as new data arrive. The design is based on discussions with @tdas and @mengxr, in which we determined how to add this functionality in a general way, with minimal changes to existing libraries.\r\n\r\n__Summary of additions:__\r\n\r\n_StreamingRegression_\r\n- An abstract class for fitting regression analyses online on streaming data, including training on (and updating) a model, and making predictions\r\n\r\n_StreamingLinearRegressionWithSGD_\r\n- Class and companion object for running streaming linear regression\r\n\r\n_MLStreamingUtils_\r\n- Utility for loading and parsing streaming data from a text file stream, could be extended with functions for loading data from Kafka, Network, etc.\r\n\r\n_StreamingLinearRegression_\r\n- Example use case: fitting a model online to data from one stream, and making predictions on other data\r\n\r\n__Notes__\r\n- I will definitely add tests but I wasn't sure where it makes sense to put them: mllib or streaming?\r\n- If this looks good, I can use the StreamingRegression class to do all other regression analyses (Ridge, Lasso, etc.), and a similar StreamingClassification class would give us logistic and SVM classification.","created_at":"2014-07-10T19:53:46Z","updated_at":"2014-07-30T03:49:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98592d11829ef379f34f1c1e771f52a632438eaf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/1361/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/1361/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments/{number}","comments_url":"https://api.github.com/repos/apache/spark/issues/1361/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/a2a63ad827994c86d517b7227c064420b80117c1","head":{"label":"freeman-lab:streaming-mllib","ref":"streaming-mllib","sha":"a2a63ad827994c86d517b7227c064420b80117c1","user":{"login":"freeman-lab","id":3387500,"avatar_url":"https://avatars.githubusercontent.com/u/3387500?v=1","gravatar_id":"f19e21b5a19032902638f1fb2c4ee49f","url":"https://api.github.com/users/freeman-lab","html_url":"https://github.com/freeman-lab","followers_url":"https://api.github.com/users/freeman-lab/followers","following_url":"https://api.github.com/users/freeman-lab/following{/other_user}","gists_url":"https://api.github.com/users/freeman-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/freeman-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeman-lab/subscriptions","organizations_url":"https://api.github.com/users/freeman-lab/orgs","repos_url":"https://api.github.com/users/freeman-lab/repos","events_url":"https://api.github.com/users/freeman-lab/events{/privacy}","received_events_url":"https://api.github.com/users/freeman-lab/received_events","type":"User","site_admin":false},"repo":{"id":19164705,"name":"spark","full_name":"freeman-lab/spark","owner":{"login":"freeman-lab","id":3387500,"avatar_url":"https://avatars.githubusercontent.com/u/3387500?v=1","gravatar_id":"f19e21b5a19032902638f1fb2c4ee49f","url":"https://api.github.com/users/freeman-lab","html_url":"https://github.com/freeman-lab","followers_url":"https://api.github.com/users/freeman-lab/followers","following_url":"https://api.github.com/users/freeman-lab/following{/other_user}","gists_url":"https://api.github.com/users/freeman-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/freeman-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeman-lab/subscriptions","organizations_url":"https://api.github.com/users/freeman-lab/orgs","repos_url":"https://api.github.com/users/freeman-lab/repos","events_url":"https://api.github.com/users/freeman-lab/events{/privacy}","received_events_url":"https://api.github.com/users/freeman-lab/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/freeman-lab/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/freeman-lab/spark","forks_url":"https://api.github.com/repos/freeman-lab/spark/forks","keys_url":"https://api.github.com/repos/freeman-lab/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/freeman-lab/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/freeman-lab/spark/teams","hooks_url":"https://api.github.com/repos/freeman-lab/spark/hooks","issue_events_url":"https://api.github.com/repos/freeman-lab/spark/issues/events{/number}","events_url":"https://api.github.com/repos/freeman-lab/spark/events","assignees_url":"https://api.github.com/repos/freeman-lab/spark/assignees{/user}","branches_url":"https://api.github.com/repos/freeman-lab/spark/branches{/branch}","tags_url":"https://api.github.com/repos/freeman-lab/spark/tags","blobs_url":"https://api.github.com/repos/freeman-lab/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/freeman-lab/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/freeman-lab/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/freeman-lab/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/freeman-lab/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/freeman-lab/spark/languages","stargazers_url":"https://api.github.com/repos/freeman-lab/spark/stargazers","contributors_url":"https://api.github.com/repos/freeman-lab/spark/contributors","subscribers_url":"https://api.github.com/repos/freeman-lab/spark/subscribers","subscription_url":"https://api.github.com/repos/freeman-lab/spark/subscription","commits_url":"https://api.github.com/repos/freeman-lab/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/freeman-lab/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/freeman-lab/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/freeman-lab/spark/issues/comments/{number}","contents_url":"https://api.github.com/repos/freeman-lab/spark/contents/{+path}","compare_url":"https://api.github.com/repos/freeman-lab/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/freeman-lab/spark/merges","archive_url":"https://api.github.com/repos/freeman-lab/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/freeman-lab/spark/downloads","issues_url":"https://api.github.com/repos/freeman-lab/spark/issues{/number}","pulls_url":"https://api.github.com/repos/freeman-lab/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/freeman-lab/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/freeman-lab/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/freeman-lab/spark/labels{/name}","releases_url":"https://api.github.com/repos/freeman-lab/spark/releases{/id}","created_at":"2014-04-26T00:21:43Z","updated_at":"2014-06-04T00:59:48Z","pushed_at":"2014-07-18T00:51:48Z","git_url":"git://github.com/freeman-lab/spark.git","ssh_url":"git@github.com:freeman-lab/spark.git","clone_url":"https://github.com/freeman-lab/spark.git","svn_url":"https://github.com/freeman-lab/spark","homepage":null,"size":70373,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"88006a62377d2b7c9886ba49ceef158737bc1b97","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=1","gravatar_id":"a676c0bf448fcd49f588249ead719b4c","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=1","gravatar_id":"a676c0bf448fcd49f588249ead719b4c","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments/{number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2014-07-30T03:09:44Z","pushed_at":"2014-07-30T02:05:17Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":2434412,"stargazers_count":914,"watchers_count":914,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":952,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":271,"forks":952,"open_issues":271,"watchers":914,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/1361"},"html":{"href":"https://github.com/apache/spark/pull/1361"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/1361"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/1361/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/1361/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/1361/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/a2a63ad827994c86d517b7227c064420b80117c1"}}}}