{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/83579367","pull_request_review_id":4413465,"id":83579367,"diff_hunk":"@@ -137,18 +143,67 @@ class KMeansSuite extends SparkFunSuite with MLlibTestSparkContext with DefaultR\n       assert(model.clusterCenters === model2.clusterCenters)\n     }\n     val kmeans = new KMeans()\n-    testEstimatorAndModelReadWrite(kmeans, dataset, KMeansSuite.allParamSettings, checkModelData)\n+    testEstimatorAndModelReadWrite(kmeans, dataset, KMeansSuite.allParamSettings, checkModelData,\n+      Map(\"initialModel\" -> (checkModelData _).asInstanceOf[(Any, Any) => Unit]))\n+  }\n+\n+  test(\"Initialize using a trained model\") {\n+    val kmeans = new KMeans().setK(k).setSeed(1).setMaxIter(1)\n+    val oneIterModel = kmeans.fit(dataset)\n+    val twoIterModel = kmeans.copy(ParamMap(ParamPair(kmeans.maxIter, 2))).fit(dataset)\n+    val oneMoreIterModel = kmeans.setInitialModel(oneIterModel).fit(dataset)\n+\n+    assert(oneMoreIterModel.getK === k)\n+\n+    twoIterModel.clusterCenters.zip(oneMoreIterModel.clusterCenters)\n+      .foreach { case (center1, center2) => assert(center1 ~== center2 absTol 1E-8) }\n+  }\n+\n+  test(\"Initialize using a model with wrong dimension of cluster centers\") {\n+    val kmeans = new KMeans().setK(k).setSeed(1).setMaxIter(1)\n+\n+    val wrongDimModel = KMeansSuite.generateRandomKMeansModel(4, k)\n+    val wrongDimModelThrown = intercept[IllegalArgumentException] {\n+      kmeans.setInitialModel(wrongDimModel).fit(dataset)\n+    }\n+    assert(wrongDimModelThrown.getMessage.contains(\"mismatched dimension\"))\n+  }\n+\n+  test(\"Infer K from an initial model\") {\n+    val kmeans = new KMeans().setK(5)\n+    val testNewK = 10\n+    val randomModel = KMeansSuite.generateRandomKMeansModel(dim, testNewK)\n+    assert(kmeans.setInitialModel(randomModel).getK === testNewK)\n+  }\n+\n+  test(\"Ignore k if initialModel is set\") {\n+    val kmeans = new KMeans()\n+\n+    val m1 = KMeansSuite.generateRandomKMeansModel(dim, k)","path":"mllib/src/test/scala/org/apache/spark/ml/clustering/KMeansSuite.scala","position":75,"original_position":75,"commit_id":"261fcfa4e96fe901f1866eb56ac87917935bf28b","original_commit_id":"261fcfa4e96fe901f1866eb56ac87917935bf28b","user":{"login":"sethah","id":7275795,"avatar_url":"https://avatars.githubusercontent.com/u/7275795?v=3","gravatar_id":"","url":"https://api.github.com/users/sethah","html_url":"https://github.com/sethah","followers_url":"https://api.github.com/users/sethah/followers","following_url":"https://api.github.com/users/sethah/following{/other_user}","gists_url":"https://api.github.com/users/sethah/gists{/gist_id}","starred_url":"https://api.github.com/users/sethah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethah/subscriptions","organizations_url":"https://api.github.com/users/sethah/orgs","repos_url":"https://api.github.com/users/sethah/repos","events_url":"https://api.github.com/users/sethah/events{/privacy}","received_events_url":"https://api.github.com/users/sethah/received_events","type":"User","site_admin":false},"body":"minor: call it `initialModel` instead?","created_at":"2016-10-17T05:25:38Z","updated_at":"2016-10-17T05:29:28Z","html_url":"https://github.com/apache/spark/pull/11119#discussion_r83579367","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/11119","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/83579367"},"html":{"href":"https://github.com/apache/spark/pull/11119#discussion_r83579367"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/11119"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11119","id":58661049,"html_url":"https://github.com/apache/spark/pull/11119","diff_url":"https://github.com/apache/spark/pull/11119.diff","patch_url":"https://github.com/apache/spark/pull/11119.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/11119","number":11119,"state":"open","locked":false,"title":"[SPARK-10780][ML] Add an initial model to kmeans","user":{"login":"yinxusen","id":2637239,"avatar_url":"https://avatars.githubusercontent.com/u/2637239?v=3","gravatar_id":"","url":"https://api.github.com/users/yinxusen","html_url":"https://github.com/yinxusen","followers_url":"https://api.github.com/users/yinxusen/followers","following_url":"https://api.github.com/users/yinxusen/following{/other_user}","gists_url":"https://api.github.com/users/yinxusen/gists{/gist_id}","starred_url":"https://api.github.com/users/yinxusen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yinxusen/subscriptions","organizations_url":"https://api.github.com/users/yinxusen/orgs","repos_url":"https://api.github.com/users/yinxusen/repos","events_url":"https://api.github.com/users/yinxusen/events{/privacy}","received_events_url":"https://api.github.com/users/yinxusen/received_events","type":"User","site_admin":false},"body":"https://issues.apache.org/jira/browse/SPARK-10780\r\n\r\nI mark it as WIP because there are several issues need to discuss:\r\n\r\n1. Codegen for shared params doesn't support general type. But IMHO there is no need to rewrite the codegen to support general type params, for now. So I add an `extras` in `SharedParamsCodeGen` to support this kind of exception. We may modify the codegen later if there are more general type shared parameters.\r\n\r\n2. Since we add `Model` in parameters of every `Estimator`, the save/load of estimators should be modified to support model persistence, refer to https://github.com/apache/spark/pull/9971. I ignore it in this version of the code because the save/load works well only if we don't set `initialModel`. I'll add save/load for the new parameter after the discussion.\r\n\r\n3. I don't add model check (e.g. number of centers equals to k, the dimension of centers equals to data points') here because the inner `MLlibKMeans` checks it for us. For those estimators whose MLlib companions don't provide warm-starts, we need to check the initial model in ML package.\r\n\r\n4. I add three different setters for `KMeans`. The first one uses for collaboration with model save/load, the second one is for accepting generalized model, and the third one is more user-friendly.","created_at":"2016-02-08T20:16:46Z","updated_at":"2016-10-17T05:29:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e194489433d29277816fd34613e97f605b3bbd39","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/11119/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/11119/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/11119/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/261fcfa4e96fe901f1866eb56ac87917935bf28b","head":{"label":"yinxusen:SPARK-10780","ref":"SPARK-10780","sha":"261fcfa4e96fe901f1866eb56ac87917935bf28b","user":{"login":"yinxusen","id":2637239,"avatar_url":"https://avatars.githubusercontent.com/u/2637239?v=3","gravatar_id":"","url":"https://api.github.com/users/yinxusen","html_url":"https://github.com/yinxusen","followers_url":"https://api.github.com/users/yinxusen/followers","following_url":"https://api.github.com/users/yinxusen/following{/other_user}","gists_url":"https://api.github.com/users/yinxusen/gists{/gist_id}","starred_url":"https://api.github.com/users/yinxusen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yinxusen/subscriptions","organizations_url":"https://api.github.com/users/yinxusen/orgs","repos_url":"https://api.github.com/users/yinxusen/repos","events_url":"https://api.github.com/users/yinxusen/events{/privacy}","received_events_url":"https://api.github.com/users/yinxusen/received_events","type":"User","site_admin":false},"repo":{"id":17233732,"name":"spark","full_name":"yinxusen/spark","owner":{"login":"yinxusen","id":2637239,"avatar_url":"https://avatars.githubusercontent.com/u/2637239?v=3","gravatar_id":"","url":"https://api.github.com/users/yinxusen","html_url":"https://github.com/yinxusen","followers_url":"https://api.github.com/users/yinxusen/followers","following_url":"https://api.github.com/users/yinxusen/following{/other_user}","gists_url":"https://api.github.com/users/yinxusen/gists{/gist_id}","starred_url":"https://api.github.com/users/yinxusen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yinxusen/subscriptions","organizations_url":"https://api.github.com/users/yinxusen/orgs","repos_url":"https://api.github.com/users/yinxusen/repos","events_url":"https://api.github.com/users/yinxusen/events{/privacy}","received_events_url":"https://api.github.com/users/yinxusen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yinxusen/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/yinxusen/spark","forks_url":"https://api.github.com/repos/yinxusen/spark/forks","keys_url":"https://api.github.com/repos/yinxusen/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yinxusen/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yinxusen/spark/teams","hooks_url":"https://api.github.com/repos/yinxusen/spark/hooks","issue_events_url":"https://api.github.com/repos/yinxusen/spark/issues/events{/number}","events_url":"https://api.github.com/repos/yinxusen/spark/events","assignees_url":"https://api.github.com/repos/yinxusen/spark/assignees{/user}","branches_url":"https://api.github.com/repos/yinxusen/spark/branches{/branch}","tags_url":"https://api.github.com/repos/yinxusen/spark/tags","blobs_url":"https://api.github.com/repos/yinxusen/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yinxusen/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yinxusen/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/yinxusen/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yinxusen/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/yinxusen/spark/languages","stargazers_url":"https://api.github.com/repos/yinxusen/spark/stargazers","contributors_url":"https://api.github.com/repos/yinxusen/spark/contributors","subscribers_url":"https://api.github.com/repos/yinxusen/spark/subscribers","subscription_url":"https://api.github.com/repos/yinxusen/spark/subscription","commits_url":"https://api.github.com/repos/yinxusen/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/yinxusen/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/yinxusen/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/yinxusen/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/yinxusen/spark/contents/{+path}","compare_url":"https://api.github.com/repos/yinxusen/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yinxusen/spark/merges","archive_url":"https://api.github.com/repos/yinxusen/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yinxusen/spark/downloads","issues_url":"https://api.github.com/repos/yinxusen/spark/issues{/number}","pulls_url":"https://api.github.com/repos/yinxusen/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/yinxusen/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/yinxusen/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yinxusen/spark/labels{/name}","releases_url":"https://api.github.com/repos/yinxusen/spark/releases{/id}","deployments_url":"https://api.github.com/repos/yinxusen/spark/deployments","created_at":"2014-02-27T02:30:58Z","updated_at":"2015-12-19T01:15:28Z","pushed_at":"2016-10-17T04:20:00Z","git_url":"git://github.com/yinxusen/spark.git","ssh_url":"git@github.com:yinxusen/spark.git","clone_url":"https://github.com/yinxusen/spark.git","svn_url":"https://github.com/yinxusen/spark","homepage":null,"size":235820,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"095862a3cff73fd88db9ed37a63e7629e664ff64","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","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=3","gravatar_id":"","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}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-10-17T05:26:59Z","pushed_at":"2016-10-17T05:24:20Z","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":596500,"stargazers_count":10383,"watchers_count":10383,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9646,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":475,"forks":9646,"open_issues":475,"watchers":10383,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/11119"},"html":{"href":"https://github.com/apache/spark/pull/11119"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/11119"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/11119/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/11119/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/11119/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/261fcfa4e96fe901f1866eb56ac87917935bf28b"}}}}
{"actor":{"display_login":"sethah"}}