Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/4986#discussion_r27068197
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/clustering/GaussianMixtureModel.scala
---
@@ -83,5 +95,81 @@ class GaussianMixtureModel(
p(i) /= pSum
}
p
- }
+ }
+}
+
+@Experimental
+object GaussianMixtureModel extends Loader[GaussianMixtureModel] {
+
+ private object SaveLoadV1_0 {
+
+ case class Data(weight: Double, mu: Vector, sigma: Matrix)
+
+ def formatVersionV1_0 = "1.0"
+
+ def classNameV1_0 =
"org.apache.spark.mllib.clustering.GaussianMixtureModel"
+
+ def save(
+ sc: SparkContext,
+ path: String,
+ weights: Array[Double],
+ gaussians: Array[MultivariateGaussian]): Unit = {
+
+ val sqlContext = new SQLContext(sc)
+ import sqlContext.implicits._
+
+ // Create JSON metadata.
+ val metadata = compact(render
+ (("class" -> classNameV1_0) ~ ("version" -> formatVersionV1_0) ~
("k" -> weights.length)))
+ sc.parallelize(Seq(metadata),
1).saveAsTextFile(Loader.metadataPath(path))
+
+ // Create Parquet data.
+ val dataArray = Array.tabulate(weights.length){ i =>
+ Data(weights(i), gaussians(i).mu, gaussians(i).sigma)
+ }
+ val dataRDD: DataFrame = sc.parallelize(dataArray, 1).toDF()
+ dataRDD.saveAsParquetFile(Loader.dataPath(path))
+ }
+
+ def load(sc: SparkContext, path: String) : GaussianMixtureModel = {
+ val datapath = Loader.dataPath(path)
--- End diff --
`datapath` -> `dataPath` (camelCase)
---
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]