Github user asolimando commented on a diff in the pull request:
https://github.com/apache/spark/pull/20632#discussion_r169172053
--- 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 --
Yes, it is correct.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]