public class Node
extends Object
implements scala.Serializable
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
Constructor and 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) |
Modifier and Type | Method and 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 |
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() |
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)
public static Node emptyNode(int nodeIndex)
nodeIndex
- (undocumented)public static Node apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
DecisionTree.findBestSplits
to construct child nodes
after finding the best splits for parent nodes.
Other fields are set at next level.nodeIndex
- integer node id, from 1predict
- predicted value at the nodeimpurity
- current node impurityisLeaf
- whether the node is a leafpublic static int leftChildIndex(int nodeIndex)
nodeIndex
- (undocumented)public static int rightChildIndex(int nodeIndex)
nodeIndex
- (undocumented)public static int parentIndex(int nodeIndex)
nodeIndex
- (undocumented)public static int indexToLevel(int nodeIndex)
nodeIndex
- (undocumented)public static boolean isLeftChild(int nodeIndex)
nodeIndex
- (undocumented)public static int maxNodesInLevel(int level)
level
- Level of tree (0 = root).public static int startIndexInLevel(int level)
level
- Level of tree (0 = root).public static Node getNode(int nodeIndex, Node rootNode)
nodeIndex
- (undocumented)rootNode
- (undocumented)public int id()
public Predict predict()
public double impurity()
public boolean isLeaf()
public scala.Option<Split> split()
public scala.Option<Node> leftNode()
public scala.Option<Node> rightNode()
public scala.Option<InformationGainStats> stats()
public String toString()
toString
in class Object
public double predict(Vector features)
features
- feature value