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-14312] [ML] [SparkR] NaiveBayes model p...
Date Thu, 21 Apr 2016 23:45:52 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12573#discussion_r60672598
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/r/NaiveBayesWrapper.scala ---
    @@ -74,4 +83,41 @@ private[r] object NaiveBayesWrapper {
           .fit(data)
         new NaiveBayesWrapper(pipeline, labels, features)
       }
    +
    +  override def read: MLReader[NaiveBayesWrapper] = new NaiveBayesWrapperReader
    +
    +  override def load(path: String): NaiveBayesWrapper = super.load(path)
    +
    +  class NaiveBayesWrapperWriter(instance: NaiveBayesWrapper) extends MLWriter {
    +
    +    override protected def saveImpl(path: String): Unit = {
    +      val rMetadataPath = new Path(path, "rMetadata").toString
    +      val pipelinePath = new Path(path, "pipeline").toString
    +
    +      val rMetadata = ("class" -> instance.getClass.getName) ~
    +        ("labels" -> parse(compact(render(instance.labels.toSeq)))) ~
    +        ("features" -> parse(compact(render(instance.features.toSeq))))
    +      val rMetadataJson: String = compact(render(rMetadata))
    +      sc.parallelize(Seq(rMetadataJson), 1).saveAsTextFile(rMetadataPath)
    +
    +      instance.pipeline.save(pipelinePath)
    +    }
    +  }
    +
    +  class NaiveBayesWrapperReader extends MLReader[NaiveBayesWrapper] {
    +
    +    override def load(path: String): NaiveBayesWrapper = {
    +      implicit val format = DefaultFormats
    +      val rMetadataPath = new Path(path, "rMetadata").toString
    +      val pipelinePath = new Path(path, "pipeline").toString
    +
    +      val rMetadataStr = sc.textFile(rMetadataPath, 1).first()
    +      val rMetadata = parse(rMetadataStr)
    +      val labels = parse(compact(render(rMetadata \ "labels"))).extract[Seq[String]].toArray
    --- End diff --
    
    `(rMetadata \ "labels").extract[Array[String]]` should work.


---
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