Github user feynmanliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/7320#discussion_r37817800
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/fpm/FPGrowth.scala ---
@@ -52,8 +62,74 @@ class FPGrowthModel[Item: ClassTag](val freqItemsets:
RDD[FreqItemset[Item]]) ex
val associationRules = new AssociationRules(confidence)
associationRules.run(freqItemsets)
}
+ override def save(sc: SparkContext, path: String): Unit = {
+ FPGrowthModel.SaveLoadV1_0.save(sc, this, path)
+ }
+
+ override protected def formatVersion: String = "1.0"
}
+object FPGrowthModel extends Loader[FPGrowthModel[FreqItemset[Any]]] {
+
+ override def load(sc: SparkContext, path: String):
FPGrowthModel[FreqItemset[Any]] = {
+ FPGrowthModel.SaveLoadV1_0.load(sc, path)
+ }
+
+ private case class itemCountPair[Item](items: Array[Item], freq:
Long)
+
+ private[fpm]
+ object SaveLoadV1_0 {
+
+ private val thisFormatVersion = "1.0"
+
+ private[fpm]
+ val thisClassName = "org.apache.spark.mllib.fpm.FPGrowthModel"
+
+ def save[Item: ClassTag](sc: SparkContext, model:
FPGrowthModel[Item], path: String): Unit = {
+ val sqlContext = new SQLContext(sc)
+
+ val metadata = compact(render(
+ ("class" -> thisClassName) ~ ("version" -> thisFormatVersion) ~
+ ("frequentItemsCount" -> model.freqItemsets.count())))
+ sc.parallelize(Seq(metadata),
1).saveAsTextFile(Loader.metadataPath(path))
+ val sqlType = model.freqItemsets.first().items(0) match {
+ case _: java.lang.String => StringType
--- End diff --
This code assumes that items are a primitive type, but items are currently
arbitrary. We should discuss on the JIRA whether it's acceptable to restrict
items to be primitives / types supported in `spark.sql.types`
---
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]