{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/34931021","id":34931021,"diff_hunk":"@@ -0,0 +1,114 @@\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.ml.clustering\n+\n+import org.apache.spark.SparkFunSuite\n+import org.apache.spark.mllib.clustering.{KMeans => MLlibKMeans}\n+import org.apache.spark.mllib.linalg.{Vector, Vectors}\n+import org.apache.spark.mllib.util.MLlibTestSparkContext\n+import org.apache.spark.sql.{DataFrame, SQLContext}\n+\n+private[clustering] case class TestRow(features: Vector)\n+\n+object KMeansSuite {\n+  def generateKMeansData(sql: SQLContext, rows: Int, dim: Int, k: Int): DataFrame = {\n+    val sc = sql.sparkContext\n+    val rdd = sc.parallelize(1 to rows).map(i => Vectors.dense(Array.fill(dim)((i % k).toDouble)))\n+      .map(v => new TestRow(v))\n+    sql.createDataFrame(rdd)\n+  }\n+}\n+\n+class KMeansSuite extends SparkFunSuite with MLlibTestSparkContext {\n+\n+  final val k = 5\n+  @transient var dataset: DataFrame = _\n+\n+  override def beforeAll(): Unit = {\n+    super.beforeAll()\n+\n+    dataset = KMeansSuite.generateKMeansData(sqlContext, 50, 3, k)\n+  }\n+\n+  test(\"default parameters\") {\n+    val kmeans = new KMeans()\n+\n+    assert(kmeans.getK === 2)\n+    assert(kmeans.getFeaturesCol === \"features\")\n+    assert(kmeans.getPredictionCol === \"prediction\")\n+    assert(kmeans.getMaxIter === 20)\n+    assert(kmeans.getRuns === 1)\n+    assert(kmeans.getInitMode === MLlibKMeans.K_MEANS_PARALLEL)\n+    assert(kmeans.getInitSteps === 5)\n+    assert(kmeans.getEpsilon === 1e-4)\n+  }\n+\n+  test(\"set parameters\") {\n+    val kmeans = new KMeans()\n+      .setK(9)\n+      .setFeaturesCol(\"test_feature\")\n+      .setPredictionCol(\"test_prediction\")\n+      .setMaxIter(33)\n+      .setRuns(7)\n+      .setInitMode(MLlibKMeans.RANDOM)\n+      .setInitSteps(3)\n+      .setSeed(123)\n+      .setEpsilon(1e-3)\n+\n+    assert(kmeans.getK === 9)\n+    assert(kmeans.getFeaturesCol === \"test_feature\")\n+    assert(kmeans.getPredictionCol === \"test_prediction\")\n+    assert(kmeans.getMaxIter === 33)\n+    assert(kmeans.getRuns === 7)\n+    assert(kmeans.getInitMode === MLlibKMeans.RANDOM)\n+    assert(kmeans.getInitSteps === 3)\n+    assert(kmeans.getSeed === 123)\n+    assert(kmeans.getEpsilon === 1e-3)\n+  }\n+\n+  test(\"parameters validation\") {\n+    intercept[IllegalArgumentException] {\n+      new KMeans().setK(1)\n+    }\n+    intercept[IllegalArgumentException] {\n+      new KMeans().setInitMode(\"no_such_a_mode\")\n+    }\n+    intercept[IllegalArgumentException] {\n+      new KMeans().setInitSteps(0)\n+    }\n+    intercept[IllegalArgumentException] {\n+      new KMeans().setRuns(0)\n+    }\n+  }\n+\n+  test(\"fit & transform\") {\n+    val predictionColName = \"kmeans_prediction\"\n+    val kmeans = new KMeans().setK(k).setPredictionCol(predictionColName).setSeed(1)\n+    val model = kmeans.fit(dataset)\n+    assert(model.clusterCenters.length === k)\n+\n+    val transformed = model.transform(dataset)\n+    val expectedColumns = Array(\"features\", predictionColName)\n+    expectedColumns.foreach { column =>\n+      transformed.columns.contains(column)","path":"mllib/src/test/scala/org/apache/spark/ml/clustering/KMeansSuite.scala","position":108,"original_position":108,"commit_id":"a14939bb221e87cceee16119263fae214ae6dd60","original_commit_id":"a14939bb221e87cceee16119263fae214ae6dd60","user":{"login":"jkbradley","id":5084283,"avatar_url":"https://avatars.githubusercontent.com/u/5084283?v=3","gravatar_id":"","url":"https://api.github.com/users/jkbradley","html_url":"https://github.com/jkbradley","followers_url":"https://api.github.com/users/jkbradley/followers","following_url":"https://api.github.com/users/jkbradley/following{/other_user}","gists_url":"https://api.github.com/users/jkbradley/gists{/gist_id}","starred_url":"https://api.github.com/users/jkbradley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkbradley/subscriptions","organizations_url":"https://api.github.com/users/jkbradley/orgs","repos_url":"https://api.github.com/users/jkbradley/repos","events_url":"https://api.github.com/users/jkbradley/events{/privacy}","received_events_url":"https://api.github.com/users/jkbradley/received_events","type":"User","site_admin":false},"body":"need to assert","created_at":"2015-07-17T21:05:36Z","updated_at":"2015-07-17T21:05:36Z","html_url":"https://github.com/apache/spark/pull/6756#discussion_r34931021","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6756","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/34931021"},"html":{"href":"https://github.com/apache/spark/pull/6756#discussion_r34931021"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6756"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6756","id":37428219,"html_url":"https://github.com/apache/spark/pull/6756","diff_url":"https://github.com/apache/spark/pull/6756.diff","patch_url":"https://github.com/apache/spark/pull/6756.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6756","number":6756,"state":"open","locked":false,"title":"[Spark-7879][MLlib] KMeans API for spark.ml Pipelines","user":{"login":"yu-iskw","id":1523515,"avatar_url":"https://avatars.githubusercontent.com/u/1523515?v=3","gravatar_id":"","url":"https://api.github.com/users/yu-iskw","html_url":"https://github.com/yu-iskw","followers_url":"https://api.github.com/users/yu-iskw/followers","following_url":"https://api.github.com/users/yu-iskw/following{/other_user}","gists_url":"https://api.github.com/users/yu-iskw/gists{/gist_id}","starred_url":"https://api.github.com/users/yu-iskw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yu-iskw/subscriptions","organizations_url":"https://api.github.com/users/yu-iskw/orgs","repos_url":"https://api.github.com/users/yu-iskw/repos","events_url":"https://api.github.com/users/yu-iskw/events{/privacy}","received_events_url":"https://api.github.com/users/yu-iskw/received_events","type":"User","site_admin":false},"body":"I Implemented the KMeans API for spark.ml Pipelines. But it doesn't include clustering abstractions for spark.ml (SPARK-7610). It would fit for another issues. And I'll try it later, since we are trying to add the hierarchical clustering algorithms in another issue. Thanks.\r\n\r\n[SPARK-7879] KMeans API for spark.ml Pipelines - ASF JIRA https://issues.apache.org/jira/browse/SPARK-7879","created_at":"2015-06-11T04:28:54Z","updated_at":"2015-07-17T21:05:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5088f0aa3f7866953be43319f9f2c708beb04f4c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6756/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6756/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6756/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/a14939bb221e87cceee16119263fae214ae6dd60","head":{"label":"yu-iskw:SPARK-7879","ref":"SPARK-7879","sha":"a14939bb221e87cceee16119263fae214ae6dd60","user":{"login":"yu-iskw","id":1523515,"avatar_url":"https://avatars.githubusercontent.com/u/1523515?v=3","gravatar_id":"","url":"https://api.github.com/users/yu-iskw","html_url":"https://github.com/yu-iskw","followers_url":"https://api.github.com/users/yu-iskw/followers","following_url":"https://api.github.com/users/yu-iskw/following{/other_user}","gists_url":"https://api.github.com/users/yu-iskw/gists{/gist_id}","starred_url":"https://api.github.com/users/yu-iskw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yu-iskw/subscriptions","organizations_url":"https://api.github.com/users/yu-iskw/orgs","repos_url":"https://api.github.com/users/yu-iskw/repos","events_url":"https://api.github.com/users/yu-iskw/events{/privacy}","received_events_url":"https://api.github.com/users/yu-iskw/received_events","type":"User","site_admin":false},"repo":{"id":20396045,"name":"spark","full_name":"yu-iskw/spark","owner":{"login":"yu-iskw","id":1523515,"avatar_url":"https://avatars.githubusercontent.com/u/1523515?v=3","gravatar_id":"","url":"https://api.github.com/users/yu-iskw","html_url":"https://github.com/yu-iskw","followers_url":"https://api.github.com/users/yu-iskw/followers","following_url":"https://api.github.com/users/yu-iskw/following{/other_user}","gists_url":"https://api.github.com/users/yu-iskw/gists{/gist_id}","starred_url":"https://api.github.com/users/yu-iskw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yu-iskw/subscriptions","organizations_url":"https://api.github.com/users/yu-iskw/orgs","repos_url":"https://api.github.com/users/yu-iskw/repos","events_url":"https://api.github.com/users/yu-iskw/events{/privacy}","received_events_url":"https://api.github.com/users/yu-iskw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yu-iskw/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/yu-iskw/spark","forks_url":"https://api.github.com/repos/yu-iskw/spark/forks","keys_url":"https://api.github.com/repos/yu-iskw/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yu-iskw/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yu-iskw/spark/teams","hooks_url":"https://api.github.com/repos/yu-iskw/spark/hooks","issue_events_url":"https://api.github.com/repos/yu-iskw/spark/issues/events{/number}","events_url":"https://api.github.com/repos/yu-iskw/spark/events","assignees_url":"https://api.github.com/repos/yu-iskw/spark/assignees{/user}","branches_url":"https://api.github.com/repos/yu-iskw/spark/branches{/branch}","tags_url":"https://api.github.com/repos/yu-iskw/spark/tags","blobs_url":"https://api.github.com/repos/yu-iskw/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yu-iskw/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yu-iskw/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/yu-iskw/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yu-iskw/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/yu-iskw/spark/languages","stargazers_url":"https://api.github.com/repos/yu-iskw/spark/stargazers","contributors_url":"https://api.github.com/repos/yu-iskw/spark/contributors","subscribers_url":"https://api.github.com/repos/yu-iskw/spark/subscribers","subscription_url":"https://api.github.com/repos/yu-iskw/spark/subscription","commits_url":"https://api.github.com/repos/yu-iskw/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/yu-iskw/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/yu-iskw/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/yu-iskw/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/yu-iskw/spark/contents/{+path}","compare_url":"https://api.github.com/repos/yu-iskw/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yu-iskw/spark/merges","archive_url":"https://api.github.com/repos/yu-iskw/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yu-iskw/spark/downloads","issues_url":"https://api.github.com/repos/yu-iskw/spark/issues{/number}","pulls_url":"https://api.github.com/repos/yu-iskw/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/yu-iskw/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/yu-iskw/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yu-iskw/spark/labels{/name}","releases_url":"https://api.github.com/repos/yu-iskw/spark/releases{/id}","created_at":"2014-06-02T07:24:57Z","updated_at":"2014-07-25T08:42:00Z","pushed_at":"2015-07-17T05:50:32Z","git_url":"git://github.com/yu-iskw/spark.git","ssh_url":"git@github.com:yu-iskw/spark.git","clone_url":"https://github.com/yu-iskw/spark.git","svn_url":"https://github.com/yu-iskw/spark","homepage":null,"size":108194,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"1b0c8e61040bf06213f9758f775679dcc41b0cce","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-07-17T13:49:35Z","pushed_at":"2015-07-17T21:01:18Z","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":1530568,"stargazers_count":4778,"watchers_count":4778,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4273,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":337,"forks":4273,"open_issues":337,"watchers":4778,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6756"},"html":{"href":"https://github.com/apache/spark/pull/6756"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6756"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6756/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6756/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6756/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/a14939bb221e87cceee16119263fae214ae6dd60"}}}}