Class Node
Object
org.apache.spark.mllib.tree.model.Node
- All Implemented Interfaces:
- 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 SummaryNested classes/interfaces inherited from interface org.apache.spark.internal.Loggingorg.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic NodeConstruct a node with nodeIndex, predict, impurity and isLeaf parameters.static NodeemptyNode(int nodeIndex) Return a node with the given node id (but nothing else set).static NodeTraces down from a root node to get the node with the given node index.intid()doubleimpurity()static intindexToLevel(int nodeIndex) Return the level of a tree which the given node is in.booleanisLeaf()static booleanisLeftChild(int nodeIndex) Returns true if this is a left child.static intleftChildIndex(int nodeIndex) Return the index of the left child of this node.scala.Option<Node>leftNode()static intmaxNodesInLevel(int level) Return the maximum number of nodes which can be in the given level of the tree.static intparentIndex(int nodeIndex) Get the parent index of the given node, or 0 if it is the root.predict()doublepredict value if node is not leafstatic intrightChildIndex(int nodeIndex) Return the index of the right child of this node.scala.Option<Node>scala.Option<Split>split()static intstartIndexInLevel(int level) Return the index of the first node in the given level.scala.Option<InformationGainStats>stats()toString()Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.spark.internal.LogginginitializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContext
- 
Constructor Details- 
Nodepublic 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- 
emptyNodeReturn a node with the given node id (but nothing else set).- Parameters:
- nodeIndex- (undocumented)
- Returns:
- (undocumented)
 
- 
applyConstruct a node with nodeIndex, predict, impurity and isLeaf parameters. This is used inDecisionTree.findBestSplitsto 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
 
- 
leftChildIndexpublic static int leftChildIndex(int nodeIndex) Return the index of the left child of this node.- Parameters:
- nodeIndex- (undocumented)
- Returns:
- (undocumented)
 
- 
rightChildIndexpublic static int rightChildIndex(int nodeIndex) Return the index of the right child of this node.- Parameters:
- nodeIndex- (undocumented)
- Returns:
- (undocumented)
 
- 
parentIndexpublic 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)
 
- 
indexToLevelpublic static int indexToLevel(int nodeIndex) Return the level of a tree which the given node is in.- Parameters:
- nodeIndex- (undocumented)
- Returns:
- (undocumented)
 
- 
isLeftChildpublic static boolean isLeftChild(int nodeIndex) Returns true if this is a left child. Note: Returns false for the root.- Parameters:
- nodeIndex- (undocumented)
- Returns:
- (undocumented)
 
- 
maxNodesInLevelpublic 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)
 
- 
startIndexInLevelpublic 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)
 
- 
getNodeTraces 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)
 
- 
idpublic int id()
- 
predict
- 
impuritypublic double impurity()
- 
isLeafpublic boolean isLeaf()
- 
split
- 
leftNode
- 
rightNode
- 
stats
- 
toString
- 
predictpredict value if node is not leaf- Parameters:
- features- feature value
- Returns:
- predicted value
 
 
-