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

    https://github.com/apache/spark/pull/20632#discussion_r169091069
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/tree/Node.scala ---
    @@ -287,6 +291,34 @@ private[tree] class LearningNode(
         }
       }
     
    +  /**
    +   * @return true iff the node is a leaf.
    +   */
    +  private def isLeafNode(): Boolean = leftChild.isEmpty && 
rightChild.isEmpty
    +
    +  // the set of (leaf) predictions appearing in the subtree rooted at the 
given node.
    +  private lazy val leafPredictions: Set[Double] = {
    +
    +    val predBuffer = new scala.collection.mutable.HashSet[Double]
    +
    +    // collect the (leaf) predictions in the left subtree, if any
    +    if (leftChild.isDefined) {
    +      predBuffer ++= leftChild.get.leafPredictions
    +    }
    +
    +    // collect the (leaf) predictions in the right subtree, if any
    +    if (predBuffer.size <= 1 && rightChild.isDefined) {
    +      predBuffer ++= rightChild.get.leafPredictions
    +    }
    +
    +    // if the node is a leaf, collect its prediction
    +    if (predBuffer.isEmpty) {
    --- End diff --
    
    BTW is the logic here that you don't need to add the node's prediction if 
it's not a leaf, because its prediction must be contained in one of its 
children, and those predictions were already added?


---

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

Reply via email to