Mockingjay.Tree (Mockingjay v0.1.0)
A struct containing a convenient in-memory representation of a decision tree.
Each "node" in the tree is a Tree struct. A "decision" or "inner" node is any node whose
:left and :right values are a valid Tree. A "leaf" or "outer" node is any node whose :left
and :right values are nil. :left and :right must either both be nil or both be a Tree.
:id- The id of the node. This is a unique reference. This is generated automatically when using thefrom_mapfunction.:left- The left child of the node. This isnilfor leaf nodes. This is aTreefor decision nodes.:right- The right child of the node. This isnilfor leaf nodes. This is aTreefor decision nodes.:value- The value of the node:- For leaf nodes, this is the value as a number.
- For non-leaf nodes, this is a map containing the following keys:
:feature- The feature used to split the data (if it is not a leaf).:threshold- The threshold used to split the data (if it is not a leaf).
Link to this section Summary
Functions
Returns a list of nodes in BFS order. For the uses in Mockingjay, BFS is tree-level order from right to left on each level. The nodes include their children nodes.
Checks is the given child_id exists in the tree.
Returns the depth of the tree. The root node is at depth 0.
Returns the depth of the tree starting from the given level.
Returns tree nodes as a list in DFS order.
Returns a Tree struct from a map.
The map must have the appropriate required keys for the Tree struct. Any extra keys are ignored.
Returns a list of the decision nodes in the tree in BFS order.
Returns a list of the values of the decision nodes in the tree in BFS order.
Returns a list of the leaf nodes in the tree in BFS order.
Returns a list of the values of the leaf nodes in the tree in BFS order.
Traverse the tree in BFS order, applying a reducer function to each node.
Link to this section Types
Link to this section Functions
bfs(root)
Returns a list of nodes in BFS order. For the uses in Mockingjay, BFS is tree-level order from right to left on each level. The nodes include their children nodes.
child?(tree, child_id)
Checks is the given child_id exists in the tree.
depth(tree)
Returns the depth of the tree. The root node is at depth 0.
depth_from_level(tree, current_depth)
Returns the depth of the tree starting from the given level.
dfs(root)
Returns tree nodes as a list in DFS order.
from_map(t)
Returns a Tree struct from a map.
The map must have the appropriate required keys for the Tree struct. Any extra keys are ignored.
get_decision_nodes(tree)
Returns a list of the decision nodes in the tree in BFS order.
get_decision_values(tree)
Returns a list of the values of the decision nodes in the tree in BFS order.
get_leaf_nodes(tree)
Returns a list of the leaf nodes in the tree in BFS order.
get_leaf_values(tree)
Returns a list of the values of the leaf nodes in the tree in BFS order.
reduce_tree(root, acc, reducer)
Traverse the tree in BFS order, applying a reducer function to each node.