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

    https://github.com/apache/spark/pull/1673#discussion_r15628533
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/tree/model/Node.scala 
---
    @@ -91,4 +91,59 @@ class Node (
           }
         }
       }
    +
    +  /**
    +   * Get number of nodes in tree from this node, including leaf nodes.
    +   */
    +  def numNodesRecursive: Int = {
    +    if (isLeaf) {
    +      1
    +    } else {
    +      1 + leftNode.get.numNodesRecursive + rightNode.get.numNodesRecursive
    +    }
    +  }
    +
    +  /**
    +   * Get depth of tree from this node.
    +   * E.g.: Depth 0 means this is a leaf node.
    +   */
    +  def depthRecursive: Int = {
    +    if (isLeaf) {
    +      0
    +    } else {
    +      1 + math.max(leftNode.get.depthRecursive, 
rightNode.get.depthRecursive)
    +    }
    +  }
    +
    +  /**
    +   * Recursive print function.
    +   * @param indentFactor  The number of spaces to add to each level of 
indentation.
    +   */
    +  def toStringRecursive(indentFactor: Int = 0): String = {
    +
    +    def splitToString(split: Split, left: Boolean) : String = {
    +      split.featureType match {
    +        case Continuous => if (left) {
    +          s"(feature ${split.feature} <= ${split.threshold})"
    +        } else {
    +          s"(feature ${split.feature} > ${split.threshold})"
    +        }
    +        case Categorical => if (left) {
    +          s"(feature ${split.feature} in ${split.categories})"
    --- End diff --
    
    The string may contain `List(...)`, which can be removed by calling 
`split.categories.mkString("{",",","}")`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to