Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/6948#discussion_r34728771
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/clustering/LDASuite.scala ---
@@ -213,6 +214,45 @@ class LDASuite extends SparkFunSuite with
MLlibTestSparkContext {
}
}
+ test("model save/load") {
+ // Test for LocalLDAModel.
+ val localModel = new LocalLDAModel(tinyTopics)
+ val tempDir1 = Utils.createTempDir()
+ val path1 = tempDir1.toURI.toString
+
+ // Test for DistributedLDAModel.
+ val k = 3
+ val topicSmoothing = 1.2
+ val termSmoothing = 1.2
+ val lda = new LDA()
+ lda.setK(k)
+ .setDocConcentration(topicSmoothing)
+ .setTopicConcentration(termSmoothing)
+ .setMaxIterations(5)
+ .setSeed(12345)
+ val corpus = sc.parallelize(tinyCorpus, 2)
+ val distributedModel: DistributedLDAModel =
lda.run(corpus).asInstanceOf[DistributedLDAModel]
+ val tempDir2 = Utils.createTempDir()
+ val path2 = tempDir2.toURI.toString
+
+ try {
+ localModel.save(sc, path1)
+ distributedModel.save(sc, path2)
+ val samelocalModel = LocalLDAModel.load(sc, path1)
+ assert(samelocalModel.topicsMatrix === localModel.topicsMatrix)
+ assert(samelocalModel.k === localModel.k)
+ assert(samelocalModel.vocabSize === localModel.vocabSize)
+
+ val sameDistributedModel = DistributedLDAModel.load(sc, path2)
+ assert(distributedModel.topicsMatrix ===
sameDistributedModel.topicsMatrix)
--- End diff --
right
---
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]