zhengruifeng commented on a change in pull request #25383: [SPARK-13677][ML]
Implement Tree-Based Feature Transformation for ML
URL: https://github.com/apache/spark/pull/25383#discussion_r312771157
##########
File path: mllib/src/main/scala/org/apache/spark/ml/tree/treeModels.scala
##########
@@ -78,6 +78,28 @@ private[spark] trait DecisionTreeModel {
/** Convert to spark.mllib DecisionTreeModel (losing some information) */
private[spark] def toOld: OldDecisionTreeModel
+
+ /** Returns an iterator that traverses (DFS, left to right) the leaves
+ * in the subtree of this node.
+ */
+ private def leafIterator(node: Node): Iterator[LeafNode] = {
+ node match {
+ case l: LeafNode => Iterator.single(l)
+ case n: InternalNode =>
+ leafIterator(n.leftChild) ++ leafIterator(n.rightChild)
+ }
+ }
+
+ @transient private lazy val leafIndices: Map[LeafNode, Int] = {
Review comment:
I had impled another leaf-transformation in the .mllib side
https://github.com/apache/spark/pull/11520, and it used the sorted `leafId` as
the output.
However, in the .ml side, the `LeafNode` class do not contain a Id, and is
exposed to the end user. So I tend to leave current `LeafNode` class alone.
As to the extra memory pressure, I think its size O(#numLeaves * #numTrees)
is much smaller than the model itself.
WDYT @srowen
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]