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 Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Node
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
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()
double
predict value if node is not leafstatic int
rightChildIndex
(int nodeIndex) Return the index of the right child of this node.scala.Option<Node>
scala.Option<Split>
split()
static int
startIndexInLevel
(int level) Return the index of the first node in the given level.scala.Option<InformationGainStats>
stats()
toString()
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, 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
-
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
Return a node with the given node id (but nothing else set).- Parameters:
nodeIndex
- (undocumented)- Returns:
- (undocumented)
-
apply
Construct a node with nodeIndex, predict, impurity and isLeaf parameters. This is used inDecisionTree.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 1predict
- predicted value at the nodeimpurity
- current node impurityisLeaf
- 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
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
-
impurity
public double impurity() -
isLeaf
public boolean isLeaf() -
split
-
leftNode
-
rightNode
-
stats
-
toString
-
predict
predict value if node is not leaf- Parameters:
features
- feature value- Returns:
- predicted value
-