Github user chiwanpark commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1186#discussion_r41498464
  
    --- Diff: 
flink-staging/flink-ml/src/main/scala/org/apache/flink/ml/classification/SVM.scala
 ---
    @@ -228,6 +225,56 @@ class SVM extends Predictor[SVM] {
         parameters.add(OutputDecisionFunction, outputDecisionFunction)
         this
       }
    +
    +  override def toPMML(): PMML = {
    +    weightsOption match {
    +      case None => {
    +        throw new RuntimeException("The SVM model has not been trained. 
Call first fit" +
    +          " before calling the export operation.")
    +      }
    +      case Some(weights) => {
    +        val model = weights.collect().head
    +        val pmml = new PMML()
    +        pmml.setHeader(new Header().setDescription("Support Vector 
Machine"))
    +
    +        // define the fields
    +        val target = FieldName.create("prediction")
    +        val fields = scala.Array.ofDim[FieldName](model.size)
    +        Range(0, model.size).foreach(index =>
    +          fields(index) = FieldName.create("field_" + index)
    +        )
    +
    +        // define the data dictionary, mining schema and model
    +        val dictionary = new DataDictionary()
    +        val miningSchema = new MiningSchema()
    +        val coefficients = new Coefficients()
    +        Range(0, model.size).foreach(index => {
    +          miningSchema.addMiningFields(
    +            new 
MiningField(fields(index)).setUsageType(FieldUsageType.ACTIVE)
    +          )
    +          coefficients.addCoefficients(new 
Coefficient().setValue(model.apply(index)))
    +          dictionary.addDataFields(
    +            new DataField(fields(index), OpType.CONTINUOUS, 
DataType.DOUBLE)
    +          )
    +        })
    --- End diff --
    
    Please use `zipWithIndex` method.


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

Reply via email to