spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srowen <...@git.apache.org>
Subject [GitHub] spark pull request #20632: [SPARK-3159] added subtree pruning in the transla...
Date Mon, 19 Feb 2018 14:36:43 GMT
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-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message