Github user yinxusen commented on a diff in the pull request:
https://github.com/apache/spark/pull/5450#discussion_r28217008
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/clustering/PowerIterationClustering.scala
---
@@ -38,7 +43,63 @@ import org.apache.spark.util.random.XORShiftRandom
@Experimental
class PowerIterationClusteringModel(
val k: Int,
- val assignments: RDD[PowerIterationClustering.Assignment]) extends
Serializable
+ val assignments: RDD[PowerIterationClustering.Assignment]) extends
Saveable with Serializable {
+
+ override def save(sc: SparkContext, path: String): Unit = {
+ PowerIterationClusteringModel.SaveLoadV1_0.save(sc, this, path)
+ }
+
+ override protected def formatVersion: String = "1.0"
+}
+
+object PowerIterationClusteringModel extends
Loader[PowerIterationClusteringModel] {
+ override def load(sc: SparkContext, path: String):
PowerIterationClusteringModel = {
+ PowerIterationClusteringModel.SaveLoadV1_0.load(sc, path)
+ }
+
+ private[clustering]
+ object SaveLoadV1_0 {
+
+ private val thisFormatVersion = "1.0"
+
+ private[clustering]
+ val thisClassName =
"org.apache.spark.mllib.clustering.PowerIterationClusteringModel"
+
+ def save(sc: SparkContext, model: PowerIterationClusteringModel, path:
String): Unit = {
+ val sqlContext = new SQLContext(sc)
+ import sqlContext.implicits._
+
+ val metadata = compact(render(
+ ("class" -> thisClassName) ~ ("version" -> thisFormatVersion) ~
("k" -> model.k)))
+ sc.parallelize(Seq(metadata),
1).saveAsTextFile(Loader.metadataPath(path))
+
+ val dataRDD = model.assignments.map(x => (x.id, x.cluster)).toDF()
--- End diff --
`assignment` is not a case class, so we cannot call `toDF()` directly.
Shall I change `Assignment` into a case class?
---
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]