Package smile.base.cart
Interface Node
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DecisionNode
,InternalNode
,LeafNode
,NominalNode
,OrdinalNode
,RegressionNode
CART tree node.
-
Method Summary
Modifier and TypeMethodDescriptionint
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.dot
(StructType schema, StructField response, int id) Returns the dot representation of node.int
leaves()
Returns the number of leaf nodes in the subtree.merge()
Try to merge the children nodes and return a leaf node.Evaluate the tree over an instance.int
size()
Returns the number of samples in the node.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.
-
Method Details
-
predict
Evaluate the tree over an instance.- Parameters:
x
- the instance.- Returns:
- the leaf node that the instance falls into.
-
dot
Returns the dot representation of node.- Parameters:
schema
- the schema of dataresponse
- the schema of response variableid
- node id- Returns:
- the dot representation of node.
-
size
int size()Returns the number of samples in the node.- Returns:
- the number of samples in the node.
-
leaves
int leaves()Returns the number of leaf nodes in the subtree.- Returns:
- the number of leaf nodes in the subtree.
-
depth
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.- Returns:
- the maximum depth of the subtree.
-
deviance
double deviance()Returns the deviance of node.- Returns:
- the deviance of node.
-
merge
Node merge()Try to merge the children nodes and return a leaf node. If not able to merge, return this node itself.- Returns:
- the merged node, or this node if merge fails.
-
toString
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.- 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.
-