You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by jkbradley <gi...@git.apache.org> on 2015/10/06 23:40:28 UTC

[GitHub] spark pull request: [SPARK-10524][ML] Use the soft prediction to o...

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

    https://github.com/apache/spark/pull/8734#discussion_r41326380
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/tree/DecisionTreeSuite.scala ---
    @@ -337,12 +342,62 @@ class DecisionTreeSuite extends SparkFunSuite with MLlibTestSparkContext {
         assert(topNode.impurity !== -1.0)
     
         // set impurity and predict for child nodes
    -    assert(topNode.leftNode.get.predict.predict === 0.0)
    -    assert(topNode.rightNode.get.predict.predict === 1.0)
    +    if (topNode.leftNode.get.predict.predict === 0.0) {
    +      assert(topNode.rightNode.get.predict.predict === 1.0)
    +    } else {
    +      assert(topNode.leftNode.get.predict.predict === 1.0)
    +      assert(topNode.rightNode.get.predict.predict === 0.0)
    +    }
         assert(topNode.leftNode.get.impurity === 0.0)
         assert(topNode.rightNode.get.impurity === 0.0)
       }
     
    +  test("Use soft prediction for binary classification with ordered categorical features") {
    +    val arr = Array(
    +      LabeledPoint(0.0, Vectors.dense(1.0, 0.0, 0.0)), // left node
    +      LabeledPoint(1.0, Vectors.dense(0.0, 1.0, 1.0)), // right node
    +      LabeledPoint(0.0, Vectors.dense(2.0, 0.0, 0.0)), // left node
    +      LabeledPoint(1.0, Vectors.dense(0.0, 2.0, 1.0)), // right node
    +      LabeledPoint(1.0, Vectors.dense(1.0, 1.0, 0.0)), // left node
    +      LabeledPoint(1.0, Vectors.dense(1.0, 0.0, 2.0))) // left node
    +    val input = sc.parallelize(arr)
    +
    +    val strategy = new Strategy(algo = Classification, impurity = Gini, maxDepth = 1,
    +      numClasses = 2, categoricalFeaturesInfo = Map(0 -> 3))
    +    val metadata = DecisionTreeMetadata.buildMetadata(input, strategy)
    +    val (splits, bins) = DecisionTree.findSplitsBins(input, metadata)
    +
    +    val treeInput = TreePoint.convertToTreeRDD(input, bins, metadata)
    +    val baggedInput = BaggedPoint.convertToBaggedRDD(treeInput, 1.0, 1, false)
    +
    +    val topNode = Node.emptyNode(nodeIndex = 1)
    +    assert(topNode.predict.predict === Double.MinValue)
    +    assert(topNode.impurity === -1.0)
    +    assert(topNode.isLeaf === false)
    +
    +    val nodesForGroup = Map((0, Array(topNode)))
    +    val treeToNodeToIndexInfo = Map((0, Map(
    +      (topNode.id, new RandomForest.NodeIndexInfo(0, None))
    +    )))
    +    val nodeQueue = new mutable.Queue[(Int, Node)]()
    +    DecisionTree.findBestSplits(baggedInput, metadata, Array(topNode),
    --- End diff --
    
    Can you please update this test to call binsToBestSplit directly?  You can change it to be ```private[tree]``` so that it's callable from this test suite.


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

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org