You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by jkbradley <gi...@git.apache.org> on 2016/04/22 04:15:52 UTC
[GitHub] spark pull request: [SPARK-11940][PYSPARK][ML] Python API for ml.c...
Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/10242#discussion_r60683456
--- Diff: python/pyspark/ml/clustering.py ---
@@ -310,6 +311,374 @@ def _create_model(self, java_model):
return BisectingKMeansModel(java_model)
+class LDAModel(JavaModel):
+ """
+ A clustering model derived from the LDA method.
+
+ .. versionadded:: 2.0.0
+ """
+
+ @since("2.0.0")
+ def isDistributed(self):
+ """Indicates whether this instance is of type DistributedLDAModel"""
+ return self._call_java("isDistributed")
+
+ @since("2.0.0")
+ def vocabSize(self):
+ """Vocabulary size (number of terms or terms in the vocabulary)"""
+ return self._call_java("vocabSize")
+
+ @since("2.0.0")
+ def topicsMatrix(self):
+ """ Inferred topics, where each topic is represented by a distribution over terms.
+ This is a matrix of size vocabSize x k, where each column is a topic.
+ No guarantees are given about the ordering of the topics.
+
+ WARNING: If this model is actually a [[DistributedLDAModel]] instance produced by
+ the Expectation-Maximization ("em") [[optimizer]], then this method could involve
+ collecting a large amount of data to the driver (on the order of vocabSize x k).
+ """
+ return self._call_java("topicsMatrix")
+
+ @since("2.0.0")
+ def logLikelihood(self, dataset):
+ """Calculates a lower bound on the log likelihood of the entire corpus.
+ See Equation (16) in the Online LDA paper (Hoffman et al., 2010).
+
+ WARNING: If this model is an instance of [[DistributedLDAModel]] (produced when
+ [[optimizer]] is set to "em"), this involves collecting a large [[topicsMatrix]] to the
+ driver. This implementation may be changed in the future.
+ """
+ return self._call_java("logLikelihood", dataset)
+
+ @since("2.0.0")
+ def logPerplexity(self, dataset):
+ """Calculate an upper bound bound on perplexity. (Lower is better.)
+ See Equation (16) in the Online LDA paper (Hoffman et al., 2010).
+
+ WARNING: If this model is an instance of [[DistributedLDAModel]] (produced when
+ [[optimizer]] is set to "em"), this involves collecting a large [[topicsMatrix]] to the
+ driver. This implementation may be changed in the future.
+ """
+ return self._call_java("logPerplexity", dataset)
+
+ @since("2.0.0")
+ def describeTopics(self, maxTermsPerTopic=10):
+ """Return the topics described by their top-weighted terms.
+
+ WARNING: If vocabSize and k are large, this can return a large object!
+ """
+ return self._call_java("describeTopics", maxTermsPerTopic)
+
+ @since("2.0.0")
+ def estimatedDocConcentration(self):
+ """Value for [[docConcentration]] estimated from data.
+ If Online LDA was used and [[optimizeDocConcentration]] was set to false,
+ then this returns the fixed (given) value for the [[docConcentration]] parameter.
+ """
+ return self._call_java("estimatedDocConcentration")
+
+
+class DistributedLDAModel(LDAModel):
+ """
+ Model fitted by LDA.
+
+ .. versionadded:: 2.0.0
+ """
+ def toLocal(self):
+ return self._call_java("toLocal")
+
+
+class LocalLDAModel(LDAModel):
+ """
+ Model fitted by LDA.
+
+ .. versionadded:: 2.0.0
+ """
+ pass
+
+
+class LDA(JavaEstimator, HasFeaturesCol, HasMaxIter, HasSeed, HasCheckpointInterval):
+ """
+ Latent Dirichlet Allocation (LDA), a topic model designed for text documents.
--- End diff --
Also, you will need to modify spacing to make the bullets show up properly. newline before bulleted list + indent bullets by a space. E.g.:
```
Terminology
- "word" = "term": an element of the vocabulary
- "token": instance of a term appearing in a document
- "topic": multinomial distribution over words representing some concept
```
You can test it in spark/python/docs by running "make html"
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org