Github user chiwanpark commented on a diff in the pull request: https://github.com/apache/flink/pull/1186#discussion_r41498327 --- Diff: flink-staging/flink-ml/src/main/scala/org/apache/flink/ml/regression/MultipleLinearRegression.scala --- @@ -124,6 +121,52 @@ class MultipleLinearRegression extends Predictor[MultipleLinearRegression] { } } + + override def toPMML(): PMML = { + weightsOption match { + case None => { + throw new RuntimeException("The MultipleLinearRegression has not been fitted to the " + + "data. This is necessary to learn the weight vector of the linear function.") + } + case Some(weights) => { + val model = weights.collect().head + val pmml = new PMML() + pmml.setHeader(new Header().setDescription("Multiple Linear Regression")) + + // define the fields + val target = FieldName.create("prediction") + val fields = scala.Array.ofDim[FieldName](model.weights.size) + Range(0, model.weights.size).foreach(index => + fields(index) = FieldName.create("field_" + index) + ) + + // define the data dictionary, mining schema and regression table + val dictionary = new DataDictionary() + val miningSchema = new MiningSchema() + val regressionTable = new RegressionTable().setIntercept(model.intercept) + Range(0, model.weights.size).foreach(index => { + miningSchema.addMiningFields( + new MiningField(fields(index)).setUsageType(FieldUsageType.ACTIVE) + ) + regressionTable.addNumericPredictors( + new NumericPredictor(fields(index), model.weights(index)) + ) + dictionary.addDataFields( + new DataField(fields(index), OpType.CONTINUOUS, DataType.DOUBLE) + ) + }) + dictionary.addDataFields(new DataField(target, OpType.CONTINUOUS, DataType.DOUBLE)) + miningSchema.addMiningFields(new MiningField(target).setUsageType(FieldUsageType.PREDICTED)) + + // define the model + val pmmlModel = new RegressionModel() + .setFunctionName(MiningFunctionType.REGRESSION) --- End diff -- Maybe we should add `.setModelType(RegressionModel.ModelType.LINEAR_REGRESSION)` after this line for future of other regression model.
--- 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. ---