Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8227#discussion_r37255077
  
    --- Diff: docs/mllib-clustering.md ---
    @@ -564,6 +564,35 @@ public class JavaLDAExample {
     {% endhighlight %}
     </div>
     
    +<div data-lang="python" markdown="1">
    +{% highlight python %}
    +from pyspark.mllib.clustering import LDA
    +from pyspark.mllib.clustering import LDAModel
    +from pyspark.mllib.linalg import Vectors
    +
    +# Load and parse the data
    +data = sc.textFile("data/mllib/sample_lda_data.txt")
    +parsedData = data.map(lambda line: Vectors.dense([float(x) for x in 
line.strip().split(' ')]))
    +# Index documents with unique IDs
    +corpus = parsedData.zipWithIndex().map(lambda x: [x[1], x[0]]).cache()
    +
    +# Cluster the documents into three topics using LDA
    +ldaModel = LDA.train(corpus, k=3)
    +
    +# Output topics. Each is a distribution over words (matching word count 
vectors)
    +print("Learned topics (as distributions over vocab of " + 
str(ldaModel.vocabSize()) + " words):")
    +topics = ldaModel.topicsMatrix()
    +for topic in range(3):
    +   print("Topic " + str(topic) + ":")
    --- End diff --
    
    Do not use tab. Use 4 spaces instead.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to