org.apache.spark.mllib.tree.model
Class Node

Object
  extended by org.apache.spark.mllib.tree.model.Node
All Implemented Interfaces:
java.io.Serializable, Logging

public class Node
extends Object
implements scala.Serializable, Logging

:: DeveloperApi :: 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:
Serialized Form

Constructor Summary
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
static Node apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
          Construct a node with nodeIndex, predict, impurity and isLeaf parameters.
 void build(Node[] nodes)
          build the left node and right nodes if not leaf
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 impurity()
           
static int indexToLevel(int nodeIndex)
          Return the level of a tree which the given node is in.
 boolean isLeaf()
           
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> leftNode()
           
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.
 Predict predict()
           
 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> rightNode()
           
 scala.Option<Split> split()
           
static int startIndexInLevel(int level)
          Return the index of the first node in the given level.
 scala.Option<InformationGainStats> stats()
           
 String toString()
           
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.spark.Logging
initializeIfNecessary, initializeLogging, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
 

Constructor Detail

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 Detail

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

build

public void build(Node[] nodes)
build the left node and right nodes if not leaf

Parameters:
nodes - array of nodes

predict

public double predict(Vector features)
predict value if node is not leaf

Parameters:
features - feature value
Returns:
predicted value