Skip to content

Commit

Permalink
added javadoc and export model type in case there is a need to support
Browse files Browse the repository at this point in the history
other types of export (not just PMML)
  • Loading branch information
selvinsource committed Oct 18, 2014
1 parent a0e3679 commit 226e184
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import java.io.OutputStream

trait ModelExport {

/**
* Write the exported model to the output stream specified
*/
def save(outputStream: OutputStream): Unit

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ package org.apache.spark.mllib.export

import org.apache.spark.mllib.clustering.KMeansModel
import org.apache.spark.mllib.export.pmml.KMeansPMMLModelExport
import org.apache.spark.mllib.export.ModelExportType._

object ModelExportFactory {

//TODO: introduce model export typed

def createModelExport(model: Any): ModelExport = model match {
case kmeans: KMeansModel => new KMeansPMMLModelExport
case _ => throw new IllegalArgumentException("Export not supported for model " + model.getClass)
/**
* Factory object to help creating the necessary ModelExport implementation
* taking as input the ModelExportType (for example PMML) and the machine learning model (for example KMeansModel).
*/
def createModelExport(model: Any, exportType: ModelExportType): ModelExport = {
return exportType match{
case PMML => model match{
case kmeans: KMeansModel => new KMeansPMMLModelExport(kmeans)
case _ => throw new IllegalArgumentException("Export not supported for model: " + model.getClass)
}
case _ => throw new IllegalArgumentException("Export type not supported:" + exportType)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.apache.spark.mllib.export

/**
* Defines export types.
* - PMML exports the machine learning models in an XML-based file format called Predictive Model Markup Language developed by the Data Mining Group (www.dmg.org).
*/
object ModelExportType extends Enumeration{

type ModelExportType = Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@

package org.apache.spark.mllib.export.pmml

class KMeansPMMLModelExport extends PMMLModelExport{
import org.apache.spark.mllib.clustering.KMeansModel

populateKMeansPMML();
/**
* PMML Model Export for KMeansModel class
*/
class KMeansPMMLModelExport(model : KMeansModel) extends PMMLModelExport{

/**
* Export the input KMeansModel model to PMML format
*/
populateKMeansPMML(model);

def populateKMeansPMML(): Unit = {
private def populateKMeansPMML(model : KMeansModel): Unit = {
//TODO: set here header description
pmml.setVersion("testing... kmeans...");
//TODO: generate the model...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ import scala.beans.BeanProperty

trait PMMLModelExport extends ModelExport{

/**
* Holder of the exported model in PMML format
*/
@BeanProperty
var pmml: PMML = new PMML();
//TODO: set here header app copyright and timestamp

/**
* Write the exported model (in PMML XML) to the output stream specified
*/
@Override
def save(outputStream: OutputStream): Unit = {
JAXBUtil.marshalPMML(pmml, new StreamResult(outputStream));
}
Expand Down

0 comments on commit 226e184

Please sign in to comment.