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

    https://github.com/apache/spark/pull/7842#discussion_r43216191
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/pmml/export/DecisionTreePMMLModelExportSuite.scala
 ---
    @@ -0,0 +1,431 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.mllib.pmml.export
    +
    +import scala.collection.JavaConverters._
    +
    +import org.dmg.pmml._
    +import org.dmg.pmml.CompoundPredicate.BooleanOperator
    +import org.scalatest.PrivateMethodTester
    +
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.mllib.tree.configuration.{Algo, FeatureType}
    +import org.apache.spark.mllib.tree.model.{DecisionTreeModel, Node, 
Predict, Split}
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +
    +class DecisionTreePMMLModelExportSuite extends SparkFunSuite
    +with MLlibTestSparkContext
    +with PrivateMethodTester {
    +
    +  test("PMML export should work as expected for DecisionTree model with 
regressor") {
    +
    +    // instantiate a MLLib DecisionTreeModel with Regression and with 3 
nodes with continuous
    +    // feature type
    +    val mlLeftNode = new Node(2, new Predict(0.5, 0.5), 0.2, true, None, 
None, None, None)
    +    val mlRightNode = new Node(3, new Predict(1.0, 0.5), 0.2, true, None, 
None, None, None)
    +    val split = new Split(100, 10.00, FeatureType.Continuous, Nil)
    +    val mlTopNode = new Node(1, new Predict(0.0, 0.1), 0.2, false,
    +      Some(split), Some(mlLeftNode), Some(mlRightNode), None)
    +
    +    val decisionTreeModel = new DecisionTreeModel(mlTopNode, 
Algo.Regression)
    +
    +    // get the pmml exporter for the DT and verify its the right exporter
    +    val pmmlExporterForDT = 
PMMLModelExportFactory.createPMMLModelExport(decisionTreeModel)
    +    assert(pmmlExporterForDT.isInstanceOf[DecisionTreePMMLModelExport])
    +
    +    // get the pmmlwrapper object for DT and verify the inner model is of 
type TreeModel
    +    // and basic fields are populated as expected
    +    val pmmlWrapperForDT = pmmlExporterForDT.getPmml
    +    assert(pmmlWrapperForDT.getHeader.getDescription == "decision tree")
    +    assert(!pmmlWrapperForDT.getModels.isEmpty)
    +    assert(pmmlWrapperForDT.getModels.size() == 1)
    +    val pmmlModelForDT = pmmlWrapperForDT.getModels.get(0)
    +    assert(pmmlModelForDT.isInstanceOf[TreeModel])
    +
    +    // validate the inner tree model fields are populated as expected
    +    val pmmlTreeModel = pmmlModelForDT.asInstanceOf[TreeModel]
    +    assert(pmmlTreeModel.getFunctionName == MiningFunctionType.REGRESSION)
    +
    +    // validate the root PMML node is populated as expected
    +    val pmmlRootNode = pmmlTreeModel.getNode
    +    assert(pmmlRootNode != null)
    +    assert(pmmlRootNode.getNodes != null && pmmlRootNode.getNodes.size() 
== 2)
    +    assert(pmmlRootNode.getId === "1")
    +    // validate the root node predicate is populated as expected
    +    val predicate = pmmlRootNode.getPredicate()
    +    assert(predicate != null)
    +    assert(predicate.isInstanceOf[True])
    +
    +    // validate the left node is populated as expected
    +    val pmmlLeftNode = pmmlRootNode.getNodes.get(0)
    +    assert(pmmlLeftNode != null)
    +    assert(!pmmlLeftNode.hasNodes)
    +    assert(pmmlLeftNode.getId === "2")
    +    assert(pmmlLeftNode.getScore == "0.5")
    +    val predicate1 = pmmlLeftNode.getPredicate
    +    assert(predicate1 != null)
    +    assert(predicate1.isInstanceOf[SimplePredicate])
    +    assert(predicate1.asInstanceOf[SimplePredicate].getField.getValue === 
"field_100")
    +    assert(predicate1.asInstanceOf[SimplePredicate].getValue === "10.0")
    +    assert(predicate1.asInstanceOf[SimplePredicate].getOperator == 
SimplePredicate.Operator
    +          .LESS_OR_EQUAL)
    --- End diff --
    
    the indent should be 2 spaces.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to