spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-5988][MLlib] add save/load for PowerIte...
Date Mon, 13 Apr 2015 07:35:03 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5450#discussion_r28219216
  
    --- 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 --
    
    Then call `toDF("id", "cluster")`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message