Class LeafNode

java.lang.Object
smile.base.cart.LeafNode
All Implemented Interfaces:
Serializable, Node
Direct Known Subclasses:
DecisionNode, RegressionNode

public abstract class LeafNode extends Object implements Node
A leaf node in decision tree.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    The number of samples in the node.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LeafNode(int size)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    int
    Returns the number of leaf nodes in the subtree.
    Try to merge the children nodes and return a leaf node.
    Evaluate the tree over an instance.
    int
    Returns the number of samples in the node.

    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

    deviance, dot, toString
  • Field Details

    • size

      protected final int size
      The number of samples in the node.
  • Constructor Details

    • LeafNode

      public LeafNode(int size)
      Constructor.
      Parameters:
      size - the number of samples in the node
  • Method Details

    • 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.
    • predict

      public 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.
    • 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.