Class InternalNode

java.lang.Object
smile.base.cart.InternalNode
All Implemented Interfaces:
Serializable, Node
Direct Known Subclasses:
NominalNode, OrdinalNode

public abstract class InternalNode extends Object implements Node
An internal node in CART.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    InternalNode(int feature, double score, double deviance, Node trueChild, Node falseChild)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    Returns true if the instance goes to the true branch.
    int
    Returns the maximum depth of the tree -- the number of nodes along the longest path from this node down to the farthest leaf node.
    double
    Returns the deviance of node.
    Returns the false branch child.
    int
    Returns the split feature.
    int
    Returns the number of leaf nodes in the subtree.
    Try to merge the children nodes and return a leaf node.
    abstract LeafNode
    Evaluate the tree over an instance.
    abstract InternalNode
    replace(Node trueChild, Node falseChild)
    Returns a new internal node with children replaced.
    double
    Returns the split score (reduction of impurity).
    int
    Returns the number of samples in the node.
    abstract String
    toString(StructType schema, boolean trueBranch)
    Returns the string representation of branch.
    int[]
    toString(StructType schema, StructField response, InternalNode parent, int depth, BigInteger id, List<String> lines)
    Adds the string representation (R's rpart format) to a collection.
    Returns the true branch child.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface smile.base.cart.Node

    dot
  • Constructor Details

    • InternalNode

      public InternalNode(int feature, double score, double deviance, Node trueChild, Node falseChild)
      Constructor.
      Parameters:
      feature - the index of feature column.
      score - the split score.
      deviance - the deviance.
      trueChild - the true branch child.
      falseChild - the false branch child.
  • Method Details

    • predict

      public abstract LeafNode predict(Tuple x)
      Description copied from interface: Node
      Evaluate the tree over an instance.
      Specified by:
      predict in interface Node
      Parameters:
      x - the instance.
      Returns:
      the leaf node that the instance falls into.
    • branch

      public abstract boolean branch(Tuple x)
      Returns true if the instance goes to the true branch.
      Parameters:
      x - the instance.
      Returns:
      true if the instance goes to the true branch.
    • replace

      public abstract InternalNode replace(Node trueChild, Node falseChild)
      Returns a new internal node with children replaced.
      Parameters:
      trueChild - the new true branch child.
      falseChild - the new false branch child.
      Returns:
      a new internal node with children replaced.
    • trueChild

      public Node trueChild()
      Returns the true branch child.
      Returns:
      the true branch child.
    • falseChild

      public Node falseChild()
      Returns the false branch child.
      Returns:
      the false branch child.
    • feature

      public int feature()
      Returns the split feature.
      Returns:
      the split feature.
    • score

      public double score()
      Returns the split score (reduction of impurity).
      Returns:
      the split score.
    • size

      public int size()
      Description copied from interface: Node
      Returns the number of samples in the node.
      Specified by:
      size in interface Node
      Returns:
      the number of samples in the node.
    • leaves

      public int leaves()
      Description copied from interface: Node
      Returns the number of leaf nodes in the subtree.
      Specified by:
      leaves in interface Node
      Returns:
      the number of leaf nodes in the subtree.
    • deviance

      public double deviance()
      Description copied from interface: Node
      Returns the deviance of node.
      Specified by:
      deviance in interface Node
      Returns:
      the deviance of node.
    • depth

      public int depth()
      Description copied from interface: Node
      Returns the maximum depth of the tree -- the number of nodes along the longest path from this node down to the farthest leaf node.
      Specified by:
      depth in interface Node
      Returns:
      the maximum depth of the subtree.
    • merge

      public Node merge()
      Description copied from interface: Node
      Try to merge the children nodes and return a leaf node. If not able to merge, return this node itself.
      Specified by:
      merge in interface Node
      Returns:
      the merged node, or this node if merge fails.
    • toString

      public abstract String toString(StructType schema, boolean trueBranch)
      Returns the string representation of branch.
      Parameters:
      schema - the schema of data.
      trueBranch - for true or false branch.
      Returns:
      the string representation of branch.
    • toString

      public int[] toString(StructType schema, StructField response, InternalNode parent, int depth, BigInteger id, List<String> lines)
      Description copied from interface: Node
      Adds the string representation (R's rpart format) to a collection.
      Specified by:
      toString in interface Node
      Parameters:
      schema - the schema of data
      response - the schema of response variable
      parent - the parent node
      depth - the depth of node in the tree. The root node is at depth 0.
      id - node id
      lines - the collection of node's string representation.
      Returns:
      the sample count of each class for decision tree; single element array [node size] for regression tree.