Regression Tree Class¶
This is the TPZ.Rtree class in some detail, refer to the source code for mode information and methods.
Module author: Matias Carrasco Kind
- class TPZ.Rtree(X, Y, minleaf=4, forest='yes', mstar=2, dict_dim='')¶
Creates a regression tree class instance
Parameters: - X (float or int array, 1 row per object) – Preprocessed attributes array (all columns are considered)
- Y (float) – Attribute to be predicted
- minleaf (int, def = 4) – Minimum number of objects on terminal leaf
- forest (str, ‘yes’/’no’) – Random forest key
- mstar (int) – Number of random subsample of attributes if forest is used
- dict_dim (dict) – dictionary with attributes names
- get_branch(line)¶
Get the branch in string format given a line search, where the line is a vector of attributes per individual object
Parameters: line (float) – input data line to look in the tree, same dimensions as input X Returns: str – branch array in string format, ex., [‘L’,’L’,’R’]
- get_vals(line)¶
Get the predictions given a line search, where the line is a vector of attributes per individual object
Parameters: line (float) – input data line to look in the tree, same dimensions as input X Returns: float – array with the leaf content
- leaves()¶
Return an array with all branches in string format ex: [‘L’,’R’,’L’] is a branch of depth 3 where L and R are the left or right branches
Returns: str – Array of all branches in the tree
- leaves_dim()¶
Returns an array of the used dimensions for all the the nodes on all the branches
Returns: int – Array of all the dimensions for each node on each branch
- plot_tree(itn=-1, fileout='TPZ', path='', save_png='no')¶
Plot a tree using dot (Graphviz) Saves it into a png file by default
Parameters: - itn (int) – Number of tree to be included on path, use -1 to ignore this number
- fileout (str) – Name of file for the png files
- path (str) – path for the output files
- save_png (str) – save png created by Graphviz (‘yes’/’no’)
- print_branch(branch)¶
Returns the content of a leaf on a branch (given in string format)
- save_tree(itn=-1, fileout='TPZ', path='')¶
Saves the tree
Parameters: - itn (int) – Number of tree to be included on path, use -1 to ignore this number
- fileout (str) – Name of output file
- path (str) – path for the output file