Github user feynmanliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/7760#discussion_r35836602
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/clustering/LDASuite.scala ---
@@ -281,6 +282,67 @@ class LDASuite extends SparkFunSuite with
MLlibTestSparkContext {
assert(ldaModel.logPerplexity(docs) ~== -3.690D relTol 1E-3D)
}
+ test("LocalLDAModel predict") {
+ val k = 2
+ val vocabSize = 6
+ val alpha = 0.01
+ val eta = 0.01
+ val gammaShape = 100
+ // obtained from LDA model trained in gensim, see below
+ val topics = new DenseMatrix(numRows = vocabSize, numCols = k, values
= Array(
+ 1.86738052, 1.94056535, 1.89981687, 0.0833265, 0.07405918,
0.07940597,
+ 0.15081551, 0.08637973, 0.12428538, 1.9474897, 1.94615165,
1.95204124))
+
+ def toydata: Array[(Long, Vector)] = Array(
+ Vectors.sparse(6, Array(0, 1), Array(1, 1)),
+ Vectors.sparse(6, Array(1, 2), Array(1, 1)),
+ Vectors.sparse(6, Array(0, 2), Array(1, 1)),
+ Vectors.sparse(6, Array(3, 4), Array(1, 1)),
+ Vectors.sparse(6, Array(3, 5), Array(1, 1)),
+ Vectors.sparse(6, Array(4, 5), Array(1, 1))
+ ).zipWithIndex.map { case (wordCounts, docId) => (docId.toLong,
wordCounts) }
+ val docs = sc.parallelize(toydata)
+
--- End diff --
OK
---
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]