Class Node

Object
org.apache.spark.mllib.tree.model.Node
All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, scala.Serializable

public class Node extends Object implements scala.Serializable, org.apache.spark.internal.Logging
Node in a decision tree.

About node indexing: Nodes are indexed from 1. Node 1 is the root; nodes 2, 3 are the left, right children. Node index 0 is not used.

param: id integer node id, from 1 param: predict predicted value at the node param: impurity current node impurity param: isLeaf whether the node is a leaf param: split split to calculate left and right nodes param: leftNode left child param: rightNode right child param: stats information gain stats

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging

    org.apache.spark.internal.Logging.SparkShellLoggingFilter
  • Constructor Summary

    Constructors
    Constructor
    Description
    Node(int id, Predict predict, double impurity, boolean isLeaf, scala.Option<Split> split, scala.Option<Node> leftNode, scala.Option<Node> rightNode, scala.Option<InformationGainStats> stats)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Node
    apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
    Construct a node with nodeIndex, predict, impurity and isLeaf parameters.
    static Node
    emptyNode(int nodeIndex)
    Return a node with the given node id (but nothing else set).
    static Node
    getNode(int nodeIndex, Node rootNode)
    Traces down from a root node to get the node with the given node index.
    int
    id()
     
    double
     
    static int
    indexToLevel(int nodeIndex)
    Return the level of a tree which the given node is in.
    boolean
     
    static boolean
    isLeftChild(int nodeIndex)
    Returns true if this is a left child.
    static int
    leftChildIndex(int nodeIndex)
    Return the index of the left child of this node.
    scala.Option<Node>
     
    static int
    maxNodesInLevel(int level)
    Return the maximum number of nodes which can be in the given level of the tree.
    static int
    parentIndex(int nodeIndex)
    Get the parent index of the given node, or 0 if it is the root.
     
    double
    predict(Vector features)
    predict value if node is not leaf
    static int
    rightChildIndex(int nodeIndex)
    Return the index of the right child of this node.
    scala.Option<Node>
     
    scala.Option<Split>
     
    static int
    startIndexInLevel(int level)
    Return the index of the first node in the given level.
    scala.Option<InformationGainStats>
     
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.spark.internal.Logging

    initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq
  • Constructor Details

    • Node

      public Node(int id, Predict predict, double impurity, boolean isLeaf, scala.Option<Split> split, scala.Option<Node> leftNode, scala.Option<Node> rightNode, scala.Option<InformationGainStats> stats)
  • Method Details

    • emptyNode

      public static Node emptyNode(int nodeIndex)
      Return a node with the given node id (but nothing else set).
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • apply

      public static Node apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
      Construct a node with nodeIndex, predict, impurity and isLeaf parameters. This is used in DecisionTree.findBestSplits to construct child nodes after finding the best splits for parent nodes. Other fields are set at next level.
      Parameters:
      nodeIndex - integer node id, from 1
      predict - predicted value at the node
      impurity - current node impurity
      isLeaf - whether the node is a leaf
      Returns:
      new node instance
    • leftChildIndex

      public static int leftChildIndex(int nodeIndex)
      Return the index of the left child of this node.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • rightChildIndex

      public static int rightChildIndex(int nodeIndex)
      Return the index of the right child of this node.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • parentIndex

      public static int parentIndex(int nodeIndex)
      Get the parent index of the given node, or 0 if it is the root.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • indexToLevel

      public static int indexToLevel(int nodeIndex)
      Return the level of a tree which the given node is in.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • isLeftChild

      public static boolean isLeftChild(int nodeIndex)
      Returns true if this is a left child. Note: Returns false for the root.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • maxNodesInLevel

      public static int maxNodesInLevel(int level)
      Return the maximum number of nodes which can be in the given level of the tree.
      Parameters:
      level - Level of tree (0 = root).
      Returns:
      (undocumented)
    • startIndexInLevel

      public static int startIndexInLevel(int level)
      Return the index of the first node in the given level.
      Parameters:
      level - Level of tree (0 = root).
      Returns:
      (undocumented)
    • getNode

      public static Node getNode(int nodeIndex, Node rootNode)
      Traces down from a root node to get the node with the given node index. This assumes the node exists.
      Parameters:
      nodeIndex - (undocumented)
      rootNode - (undocumented)
      Returns:
      (undocumented)
    • id

      public int id()
    • predict

      public Predict predict()
    • impurity

      public double impurity()
    • isLeaf

      public boolean isLeaf()
    • split

      public scala.Option<Split> split()
    • leftNode

      public scala.Option<Node> leftNode()
    • rightNode

      public scala.Option<Node> rightNode()
    • stats

      public scala.Option<InformationGainStats> stats()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • predict

      public double predict(Vector features)
      predict value if node is not leaf
      Parameters:
      features - feature value
      Returns:
      predicted value