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

Minor updates to the spark.mllib APIs:

1. Add `DeveloperApi` to `PMMLExportable` and add `Experimental` to `toPMML` methods.
2. Mention `RankingMetrics.of` in the `RankingMetrics` constructor.

Author: Xiangrui Meng <meng@databricks.com>

Closes #6280 from mengxr/SPARK-7537 and squashes the following commits:

1bd2583 [Xiangrui Meng] organize imports
94afa7a [Xiangrui Meng] mark all toPMML methods experimental
4c40da1 [Xiangrui Meng] mention the factory method for RankingMetrics for Java users
88c62d0 [Xiangrui Meng] add DeveloperApi to PMMLExportable

(cherry picked from commit 2ad4837cfa)
Signed-off-by: Xiangrui Meng <meng@databricks.com>
This commit is contained in:
Xiangrui Meng 2015-05-20 12:50:06 -07:00
parent 55bd1bb52e
commit b40c5ed7a7
2 changed files with 13 additions and 0 deletions

View file

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

View file

@ -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 {
/**
@ -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))