{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/47621638","id":47621638,"diff_hunk":"@@ -167,6 +167,200 @@ def getInitSteps(self):\n         return self.getOrDefault(self.initSteps)\n \n \n+class LDAModel(JavaModel):\n+    \"\"\" A clustering model derived from the LDA method.\n+\n+    Latent Dirichlet Allocation (LDA), a topic model designed for text documents.\n+    Terminology\n+    - \"word\" = \"term\": an element of the vocabulary\n+    - \"token\": instance of a term appearing in a document\n+    - \"topic\": multinomial distribution over words representing some concept\n+    References:\n+    - Original LDA paper (journal version):\n+    Blei, Ng, and Jordan.  \"Latent Dirichlet Allocation.\"  JMLR, 2003.\n+    \"\"\"\n+\n+    @since(\"1.7.0\")\n+    def isDistributed(self):\n+        \"\"\"Indicates whether this instance is of type DistributedLDAModel\"\"\"\n+        return self._call_java(\"isDistributed\")\n+\n+    @since(\"1.7.0\")\n+    def vocabSize(self):\n+        \"\"\"Vocabulary size (number of terms or terms in the vocabulary)\"\"\"\n+        return self._call_java(\"vocabSize\")\n+\n+    @since(\"1.7.0\")\n+    def topicsMatrix(self):\n+        \"\"\"Inferred topics, where each topic is represented by a distribution over terms.\"\"\"\n+        return self._call_java(\"topicsMatrix\")\n+\n+    @since(\"1.7.0\")\n+    def logLikelihood(self, dataset):\n+        \"\"\"Calculates a lower bound on the log likelihood of the entire corpus.\"\"\"\n+        return self._call_java(\"logLikelihood\", dataset)\n+\n+    @since(\"1.7.0\")\n+    def logPerplexity(self, dataset):\n+        \"\"\"Calculate an upper bound bound on perplexity.  (Lower is better.)\"\"\"\n+        return self._call_java(\"logPerplexity\", dataset)\n+\n+    @since(\"1.7.0\")\n+    def describeTopics(self, maxTermsPerTopic=10):\n+        \"\"\"Return the topics described by weighted terms.\n+\n+        WARNING: If vocabSize and k are large, this can return a large object!\n+\n+        :param maxTermsPerTopic: Maximum number of terms to collect for each topic.\n+            (default: vocabulary size)\n+        :return: Array over topics. Each topic is represented as a pair of matching arrays:\n+            (term indices, term weights in topic).\n+            Each topic's terms are sorted in order of decreasing weight.\n+        \"\"\"\n+        return self._call_java(\"describeTopics\", maxTermsPerTopic)\n+\n+\n+class DistributedLDAModel(LDAModel):\n+    \"\"\"\n+    Model fitted by LDA.\n+\n+    .. versionadded:: 1.7.0\n+    \"\"\"\n+    def toLocal(self):\n+        return self._call_java(\"toLocal\")\n+\n+\n+class LocalLDAModel(LDAModel):\n+    \"\"\"\n+    Model fitted by LDA.\n+\n+    .. versionadded:: 1.7.0\n+    \"\"\"\n+    pass\n+\n+\n+class LDA(JavaEstimator, HasFeaturesCol, HasMaxIter, HasSeed, HasCheckpointInterval):\n+    \"\"\" A clustering model derived from the LDA method.\n+\n+    Latent Dirichlet Allocation (LDA), a topic model designed for text documents.\n+    Terminology\n+    - \"word\" = \"term\": an element of the vocabulary\n+    - \"token\": instance of a term appearing in a document\n+    - \"topic\": multinomial distribution over words representing some concept\n+    References:\n+    - Original LDA paper (journal version):\n+    Blei, Ng, and Jordan.  \"Latent Dirichlet Allocation.\"  JMLR, 2003.\n+\n+    >>> from pyspark.mllib.linalg import Vectors, SparseVector\n+    >>> from pyspark.ml.clustering import LDA\n+    >>> df = sqlContext.createDataFrame([[1, Vectors.dense([0.0, 1.0])], \\\n+        [2, SparseVector(2, {0: 1.0})],], [\"id\", \"features\"])\n+    >>> lda = LDA(k=2, seed=1, optimizer=\"em\")\n+    >>> model = lda.fit(df)\n+    >>> model.isDistributed()\n+    True\n+    >>> localModel = model.toLocal()\n+    >>> localModel.isDistributed()\n+    False\n+    >>> model.vocabSize()\n+    2\n+    >>> model.describeTopics().show()\n+    +-----+-----------+--------------------+\n+    |topic|termIndices|         termWeights|\n+    +-----+-----------+--------------------+\n+    |    0|     [1, 0]|[0.50401530077160...|\n+    |    1|     [0, 1]|[0.50401530077160...|\n+    +-----+-----------+--------------------+\n+    ...\n+    >>> model.topicsMatrix()\n+    DenseMatrix(2, 2, [0.496, 0.504, 0.504, 0.496], 0)\n+\n+    .. versionadded:: 1.7.0\n+    \"\"\"\n+\n+    # a placeholder to make it appear in the generated doc\n+    k = Param(Params._dummy(), \"k\", \"number of clusters to create\")\n+    optimizer = Param(Params._dummy(), \"optimizer\", \"LDA optimizer\")\n+\n+    @keyword_only\n+    def __init__(self, featuresCol=\"features\", k=2,\n+                 optimizer=\"online\", learningOffset=5, learningDecay=0.51,\n+                 subsamplingRate=0.05, optimizeDocConcentration=True,\n+                 checkpointInterval=10, maxIter=20, seed=None):\n+        \"\"\"\n+        __init__(self, featuresCol=\"features\", predictionCol=\"prediction\", k=2, \\\n+                 initMode=\"k-means||\", initSteps=5, tol=1e-4, maxIter=20, seed=None)\n+        \"\"\"\n+        super(LDA, self).__init__()\n+        self._java_obj = self._new_java_obj(\"org.apache.spark.ml.clustering.LDA\", self.uid)\n+        self.k = Param(self, \"k\", \"number of clusters to create\")\n+        self.optimizer = Param(self, \"optimizer\", \"LDA optimizer\")\n+        self._setDefault(k=2, optimizer=\"online\", maxIter=20)\n+        kwargs = self.__init__._input_kwargs\n+        self.setParams(**kwargs)\n+\n+    def _create_model(self, java_model):\n+        if self.getOptimizer() == \"em\":\n+            return DistributedLDAModel(java_model)\n+        else:\n+            return LocalLDAModel(java_model)\n+\n+    @keyword_only\n+    @since(\"1.7.0\")\n+    def setParams(self, featuresCol=\"features\", k=2,\n+                  optimizer=\"online\", learningOffset=5, learningDecay=0.51,\n+                  subsamplingRate=0.05, optimizeDocConcentration=True,\n+                  checkpointInterval=10, maxIter=20, seed=None):\n+        \"\"\"\n+        ssetParams(self, featuresCol=\"features\", k=2,\n+                  optimizer=\"online\", learningOffset=5, learningDecay=0.51,\n+                  subsamplingRate=0.05, optimizeDocConcentration=True,\n+                  checkpointInterval=10, maxIter=20, seed=None):\n+\n+        Sets params for LDA.\n+        \"\"\"\n+        kwargs = self.setParams._input_kwargs\n+        return self._set(**kwargs)\n+\n+    @since(\"1.7.0\")\n+    def setK(self, value):\n+        \"\"\"\n+        Sets the value of :py:attr:`k`.\n+\n+        >>> algo = LDA().setK(10)\n+        >>> algo.getK()\n+        10\n+        \"\"\"\n+        self._paramMap[self.k] = value\n+        return self\n+\n+    @since(\"1.7.0\")\n+    def getK(self):\n+        \"\"\"\n+        Gets the value of `k`","path":"python/pyspark/ml/clustering.py","position":174,"original_position":174,"commit_id":"9c2bf314a24325211b690531211c32071199c5ef","original_commit_id":"9c2bf314a24325211b690531211c32071199c5ef","user":{"login":"yanboliang","id":1962026,"avatar_url":"https://avatars.githubusercontent.com/u/1962026?v=3","gravatar_id":"","url":"https://api.github.com/users/yanboliang","html_url":"https://github.com/yanboliang","followers_url":"https://api.github.com/users/yanboliang/followers","following_url":"https://api.github.com/users/yanboliang/following{/other_user}","gists_url":"https://api.github.com/users/yanboliang/gists{/gist_id}","starred_url":"https://api.github.com/users/yanboliang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanboliang/subscriptions","organizations_url":"https://api.github.com/users/yanboliang/orgs","repos_url":"https://api.github.com/users/yanboliang/repos","events_url":"https://api.github.com/users/yanboliang/events{/privacy}","received_events_url":"https://api.github.com/users/yanboliang/received_events","type":"User","site_admin":false},"body":"nit: ```Gets the value of k or its default value.```\r\nI guess you refer python/pyspark/ml/clustering.py, maybe we should also update that class.","created_at":"2015-12-15T10:51:15Z","updated_at":"2015-12-15T10:51:15Z","html_url":"https://github.com/apache/spark/pull/10242#discussion_r47621638","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/10242","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/47621638"},"html":{"href":"https://github.com/apache/spark/pull/10242#discussion_r47621638"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/10242"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/10242","id":53211591,"html_url":"https://github.com/apache/spark/pull/10242","diff_url":"https://github.com/apache/spark/pull/10242.diff","patch_url":"https://github.com/apache/spark/pull/10242.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/10242","number":10242,"state":"open","locked":false,"title":"[SPARK-11940][PYSPARK] Python API for ml.clustering.LDA","user":{"login":"zjffdu","id":164491,"avatar_url":"https://avatars.githubusercontent.com/u/164491?v=3","gravatar_id":"","url":"https://api.github.com/users/zjffdu","html_url":"https://github.com/zjffdu","followers_url":"https://api.github.com/users/zjffdu/followers","following_url":"https://api.github.com/users/zjffdu/following{/other_user}","gists_url":"https://api.github.com/users/zjffdu/gists{/gist_id}","starred_url":"https://api.github.com/users/zjffdu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zjffdu/subscriptions","organizations_url":"https://api.github.com/users/zjffdu/orgs","repos_url":"https://api.github.com/users/zjffdu/repos","events_url":"https://api.github.com/users/zjffdu/events{/privacy}","received_events_url":"https://api.github.com/users/zjffdu/received_events","type":"User","site_admin":false},"body":"Besides this issue, also fix another in issue in python/pyspark/__init__.py (should provide more informative message when no doc is defined but since annotation is added. \r\n\r\n  \r\n","created_at":"2015-12-10T03:30:09Z","updated_at":"2015-12-15T10:51:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5c7bfeb5a9a1063f252376c31a43c2e0d006600","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/10242/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/10242/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/10242/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/9c2bf314a24325211b690531211c32071199c5ef","head":{"label":"zjffdu:SPARK-11940","ref":"SPARK-11940","sha":"9c2bf314a24325211b690531211c32071199c5ef","user":{"login":"zjffdu","id":164491,"avatar_url":"https://avatars.githubusercontent.com/u/164491?v=3","gravatar_id":"","url":"https://api.github.com/users/zjffdu","html_url":"https://github.com/zjffdu","followers_url":"https://api.github.com/users/zjffdu/followers","following_url":"https://api.github.com/users/zjffdu/following{/other_user}","gists_url":"https://api.github.com/users/zjffdu/gists{/gist_id}","starred_url":"https://api.github.com/users/zjffdu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zjffdu/subscriptions","organizations_url":"https://api.github.com/users/zjffdu/orgs","repos_url":"https://api.github.com/users/zjffdu/repos","events_url":"https://api.github.com/users/zjffdu/events{/privacy}","received_events_url":"https://api.github.com/users/zjffdu/received_events","type":"User","site_admin":false},"repo":{"id":39936462,"name":"spark","full_name":"zjffdu/spark","owner":{"login":"zjffdu","id":164491,"avatar_url":"https://avatars.githubusercontent.com/u/164491?v=3","gravatar_id":"","url":"https://api.github.com/users/zjffdu","html_url":"https://github.com/zjffdu","followers_url":"https://api.github.com/users/zjffdu/followers","following_url":"https://api.github.com/users/zjffdu/following{/other_user}","gists_url":"https://api.github.com/users/zjffdu/gists{/gist_id}","starred_url":"https://api.github.com/users/zjffdu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zjffdu/subscriptions","organizations_url":"https://api.github.com/users/zjffdu/orgs","repos_url":"https://api.github.com/users/zjffdu/repos","events_url":"https://api.github.com/users/zjffdu/events{/privacy}","received_events_url":"https://api.github.com/users/zjffdu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zjffdu/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zjffdu/spark","forks_url":"https://api.github.com/repos/zjffdu/spark/forks","keys_url":"https://api.github.com/repos/zjffdu/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zjffdu/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zjffdu/spark/teams","hooks_url":"https://api.github.com/repos/zjffdu/spark/hooks","issue_events_url":"https://api.github.com/repos/zjffdu/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zjffdu/spark/events","assignees_url":"https://api.github.com/repos/zjffdu/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zjffdu/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zjffdu/spark/tags","blobs_url":"https://api.github.com/repos/zjffdu/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zjffdu/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zjffdu/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zjffdu/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zjffdu/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zjffdu/spark/languages","stargazers_url":"https://api.github.com/repos/zjffdu/spark/stargazers","contributors_url":"https://api.github.com/repos/zjffdu/spark/contributors","subscribers_url":"https://api.github.com/repos/zjffdu/spark/subscribers","subscription_url":"https://api.github.com/repos/zjffdu/spark/subscription","commits_url":"https://api.github.com/repos/zjffdu/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zjffdu/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zjffdu/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zjffdu/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zjffdu/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zjffdu/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zjffdu/spark/merges","archive_url":"https://api.github.com/repos/zjffdu/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zjffdu/spark/downloads","issues_url":"https://api.github.com/repos/zjffdu/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zjffdu/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zjffdu/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zjffdu/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zjffdu/spark/labels{/name}","releases_url":"https://api.github.com/repos/zjffdu/spark/releases{/id}","created_at":"2015-07-30T07:09:14Z","updated_at":"2015-07-30T07:10:53Z","pushed_at":"2015-12-15T10:01:14Z","git_url":"git://github.com/zjffdu/spark.git","ssh_url":"git@github.com:zjffdu/spark.git","clone_url":"https://github.com/zjffdu/spark.git","svn_url":"https://github.com/zjffdu/spark","homepage":null,"size":137039,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"2166c2a75083c2262e071a652dd52b1a33348b6e","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-12-15T10:09:57Z","pushed_at":"2015-12-15T10:41:28Z","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":389879,"stargazers_count":6582,"watchers_count":6582,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6098,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":413,"forks":6098,"open_issues":413,"watchers":6582,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/10242"},"html":{"href":"https://github.com/apache/spark/pull/10242"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/10242"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/10242/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/10242/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/10242/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/9c2bf314a24325211b690531211c32071199c5ef"}}}}