Skip to content

[SPARK-7537][MLLIB] spark.mllib API updates #6280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import org.apache.spark.rdd.RDD
* ::Experimental::
* Evaluator for ranking algorithms.
*
* Java users should use [[RankingMetrics$.of]] to create a [[RankingMetrics]] instance.
*
* @param predictionAndLabels an RDD of (predicted ranking, ground truth set) pairs.
*/
@Experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import javax.xml.transform.stream.StreamResult
import org.jpmml.model.JAXBUtil

import org.apache.spark.SparkContext
import org.apache.spark.annotation.{DeveloperApi, Experimental}
import org.apache.spark.mllib.pmml.export.PMMLModelExportFactory

/**
* :: DeveloperApi ::
* Export model to the PMML format
* Predictive Model Markup Language (PMML) is an XML-based file format
* developed by the Data Mining Group (www.dmg.org).
*/
@DeveloperApi
trait PMMLExportable {

/**
Expand All @@ -41,30 +44,38 @@ trait PMMLExportable {
}

/**
* :: Experimental ::
* Export the model to a local file in PMML format
*/
@Experimental
def toPMML(localPath: String): Unit = {
toPMML(new StreamResult(new File(localPath)))
}

/**
* :: Experimental ::
* Export the model to a directory on a distributed file system in PMML format
*/
@Experimental
def toPMML(sc: SparkContext, path: String): Unit = {
val pmml = toPMML()
sc.parallelize(Array(pmml), 1).saveAsTextFile(path)
}

/**
* :: Experimental ::
* Export the model to the OutputStream in PMML format
*/
@Experimental
def toPMML(outputStream: OutputStream): Unit = {
toPMML(new StreamResult(outputStream))
}

/**
* :: Experimental ::
* Export the model to a String in PMML format
*/
@Experimental
def toPMML(): String = {
val writer = new StringWriter
toPMML(new StreamResult(writer))
Expand Down