{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/34096458","id":34096458,"diff_hunk":"@@ -0,0 +1,202 @@\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+from pyspark.ml.util import keyword_only\n+from pyspark.ml.wrapper import JavaEstimator, JavaModel\n+from pyspark.ml.param.shared import *\n+from pyspark.mllib.common import inherit_doc\n+from pyspark.mllib.linalg import _convert_to_vector\n+\n+__all__ = ['KMeans', 'KMeansModel']\n+\n+\n+class KMeansModel(JavaModel):\n+    \"\"\"\n+    Model fitted by KMeans.\n+    \"\"\"\n+\n+    def clusterCenters(self):\n+        \"\"\"Get the cluster centers, represented as a list of NumPy arrays.\"\"\"\n+        return [c.toArray() for c in self._call_java(\"clusterCenters\")]\n+\n+\n+@inherit_doc\n+class KMeans(JavaEstimator, HasFeaturesCol, HasMaxIter, HasSeed):\n+    \"\"\"\n+    K-means Clustering\n+\n+    >>> from pyspark.mllib.linalg import Vectors\n+    >>> data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),\n+    ...         (Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]\n+    >>> df = sqlContext.createDataFrame(data, [\"features\"])\n+    >>> kmeans = KMeans().setK(2).setSeed(1).setFeaturesCol(\"features\")\n+    >>> model = kmeans.fit(df)\n+    >>> centers = model.clusterCenters()\n+    >>> len(centers)\n+    2\n+    >>> transformed = model.transform(df)\n+    >>> (transformed.columns)[0] == 'features'\n+    True\n+    >>> (transformed.columns)[1] == 'prediction'\n+    True\n+    >>> rows = sorted(transformed.collect(), key = lambda r: r[0])\n+    >>> rows[0].prediction == rows[1].prediction\n+    True\n+    >>> rows[2].prediction == rows[3].prediction\n+    True\n+    >>> kmeans.setParams(\"features\")","path":"python/pyspark/ml/clustering.py","position":61,"original_position":61,"commit_id":"2f392e116f69b6f2dfa8ff372c0288ea1f5b52a6","original_commit_id":"2f392e116f69b6f2dfa8ff372c0288ea1f5b52a6","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":"No need to test this here","created_at":"2015-07-07T22:01:31Z","updated_at":"2015-07-07T22:01:31Z","html_url":"https://github.com/apache/spark/pull/6756#discussion_r34096458","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6756","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/34096458"},"html":{"href":"https://github.com/apache/spark/pull/6756#discussion_r34096458"},"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-07T22:01:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b66cc1289307dfb4c5b544a9b0cc2b4a9a0e37a","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/2f392e116f69b6f2dfa8ff372c0288ea1f5b52a6","head":{"label":"yu-iskw:SPARK-7879","ref":"SPARK-7879","sha":"2f392e116f69b6f2dfa8ff372c0288ea1f5b52a6","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-03T04:30:37Z","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":106331,"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-07T20:25:55Z","pushed_at":"2015-07-07T22:01:03Z","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":1485318,"stargazers_count":4662,"watchers_count":4662,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4133,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":344,"forks":4133,"open_issues":344,"watchers":4662,"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/2f392e116f69b6f2dfa8ff372c0288ea1f5b52a6"}}}}