Package smile.base.cart
Class InternalNode
java.lang.Object
smile.base.cart.InternalNode
- All Implemented Interfaces:
Serializable
,Node
- Direct Known Subclasses:
NominalNode
,OrdinalNode
An internal node in CART.
- See Also:
-
Constructor Summary
ConstructorDescriptionInternalNode
(int feature, double score, double deviance, Node trueChild, Node falseChild) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
Returns true if the instance goes to the true branch.int
depth()
Returns the maximum depth of the tree -- the number of nodes along the longest path from this node down to the farthest leaf node.double
deviance()
Returns the deviance of node.Returns the false branch child.int
feature()
Returns the split feature.int
leaves()
Returns the number of leaf nodes in the subtree.merge()
Try to merge the children nodes and return a leaf node.abstract LeafNode
Evaluate the tree over an instance.abstract InternalNode
Returns a new internal node with children replaced.double
score()
Returns the split score (reduction of impurity).int
size()
Returns the number of samples in the node.abstract String
toString
(StructType schema, boolean trueBranch) Returns the string representation of branch.int[]
toString
(StructType schema, StructField response, InternalNode parent, int depth, BigInteger id, List<String> lines) Adds the string representation (R's rpart format) to a collection.Returns the true branch child.
-
Constructor Details
-
InternalNode
Constructor.- Parameters:
feature
- the index of feature column.score
- the split score.deviance
- the deviance.trueChild
- the true branch child.falseChild
- the false branch child.
-
-
Method Details
-
predict
Description copied from interface:Node
Evaluate the tree over an instance. -
branch
Returns true if the instance goes to the true branch.- Parameters:
x
- the instance.- Returns:
- true if the instance goes to the true branch.
-
replace
Returns a new internal node with children replaced.- Parameters:
trueChild
- the new true branch child.falseChild
- the new false branch child.- Returns:
- a new internal node with children replaced.
-
trueChild
Returns the true branch child.- Returns:
- the true branch child.
-
falseChild
Returns the false branch child.- Returns:
- the false branch child.
-
feature
public int feature()Returns the split feature.- Returns:
- the split feature.
-
score
public double score()Returns the split score (reduction of impurity).- Returns:
- the split score.
-
size
public int size()Description copied from interface:Node
Returns the number of samples in the node. -
leaves
public int leaves()Description copied from interface:Node
Returns the number of leaf nodes in the subtree. -
deviance
public double deviance()Description copied from interface:Node
Returns the deviance of node. -
depth
public int depth()Description copied from interface:Node
Returns the maximum depth of the tree -- the number of nodes along the longest path from this node down to the farthest leaf node. -
merge
Description copied from interface:Node
Try to merge the children nodes and return a leaf node. If not able to merge, return this node itself. -
toString
Returns the string representation of branch.- Parameters:
schema
- the schema of data.trueBranch
- for true or false branch.- Returns:
- the string representation of branch.
-
toString
public int[] toString(StructType schema, StructField response, InternalNode parent, int depth, BigInteger id, List<String> lines) Description copied from interface:Node
Adds the string representation (R's rpart format) to a collection.- Specified by:
toString
in interfaceNode
- Parameters:
schema
- the schema of dataresponse
- the schema of response variableparent
- the parent nodedepth
- the depth of node in the tree. The root node is at depth 0.id
- node idlines
- the collection of node's string representation.- Returns:
- the sample count of each class for decision tree; single element array [node size] for regression tree.
-