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

    https://github.com/apache/spark/pull/20632#discussion_r169737984
  
    --- 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] = {
    --- End diff --
    
    This is a recursive method. It essentially does this:
    
    ```scala
    def prune(node: Node): Node = {
      val left = prune(node.left)
      val right = prune(node.right)
      if (left.isLeaf && right.isLeaf && left.prediction == right.prediction) {
        new LeafNode
      } else {
        new InternalNode
      }
    }
    ```
    
    It starts pruning at the bottom and then works its way up.


---

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

Reply via email to