main content

compact regression tree -凯发k8网页登录

package: classreg.learning.regr

compact regression tree

description

compact version of a regression tree (of class regressiontree). the compact version does not include the data for training the regression tree. therefore, you cannot perform some tasks with a compact regression tree, such as cross validation. use a compact regression tree for making predictions (regressions) of new data.

construction

ctree = compact(tree) constructs a compact decision tree from a full decision tree.

input arguments

full, trained regression tree, specified as a regressiontree object constructed by fitrtree.

properties

categoricalpredictors

categorical predictor indices, specified as a vector of positive integers. categoricalpredictors contains index values indicating that the corresponding predictors are categorical. the index values are between 1 and p, where p is the number of predictors used to train the model. if none of the predictors are categorical, then this property is empty ([]).

categoricalsplit

an n-by-2 cell array, where n is the number of categorical splits in tree. each row in categoricalsplit gives left and right values for a categorical split. for each branch node with categorical split j based on a categorical predictor variable z, the left child is chosen if z is in categoricalsplit(j,1) and the right child is chosen if z is in categoricalsplit(j,2). the splits are in the same order as nodes of the tree. nodes for these splits can be found by running cuttype and selecting 'categorical' cuts from top to bottom.

children

an n-by-2 array containing the numbers of the child nodes for each node in tree, where n is the number of nodes. leaf nodes have child node 0.

cutcategories

an n-by-2 cell array of the categories used at branches in tree, where n is the number of nodes. for each branch node i based on a categorical predictor variable x, the left child is chosen if x is among the categories listed in cutcategories{i,1}, and the right child is chosen if x is among those listed in cutcategories{i,2}. both columns of cutcategories are empty for branch nodes based on continuous predictors and for leaf nodes.

cutpoint contains the cut points for 'continuous' cuts, and cutcategories contains the set of categories.

cutpoint

an n-element vector of the values used as cut points in tree, where n is the number of nodes. for each branch node i based on a continuous predictor variable x, the left child is chosen if cutpoint and the right child is chosen if x>=cutpoint(i). cutpoint is nan for branch nodes based on categorical predictors and for leaf nodes.

cuttype

an n-element cell array indicating the type of cut at each node in tree, where n is the number of nodes. for each node i, cuttype{i} is:

  • 'continuous' — if the cut is defined in the form x < v for a variable x and cut point v.

  • 'categorical' — if the cut is defined by whether a variable x takes a value in a set of categories.

  • '' — if i is a leaf node.

cutpoint contains the cut points for 'continuous' cuts, and cutcategories contains the set of categories.

cutpredictor

an n-element cell array of the names of the variables used for branching in each node in tree, where n is the number of nodes. these variables are sometimes known as cut variables. for leaf nodes, cutpredictor contains an empty character vector.

cutpoint contains the cut points for 'continuous' cuts, and cutcategories contains the set of categories.

cutpredictorindex

an n-element array of numeric indices for the variables used for branching in each node in tree, where n is the number of nodes. for more information, see cutpredictor.

expandedpredictornames

expanded predictor names, stored as a cell array of character vectors.

if the model uses encoding for categorical variables, then expandedpredictornames includes the names that describe the expanded variables. otherwise, expandedpredictornames is the same as predictornames.

isbranchnode

an n-element logical vector ib that is true for each branch node and false for each leaf node of tree.

nodeerror

an n-element vector e of the errors of the nodes in tree, where n is the number of nodes. e(i) is the misclassification probability for node i.

nodemean

an n-element numeric array with mean values in each node of tree, where n is the number of nodes in the tree. every element in nodemean is the average of the true y values over all observations in the node.

nodeprobability

an n-element vector p of the probabilities of the nodes in tree, where n is the number of nodes. the probability of a node is computed as the proportion of observations from the original data that satisfy the conditions for the node. this proportion is adjusted for any prior probabilities assigned to each class.

noderisk

an n-element vector of the risk of the nodes in the tree, where n is the number of nodes. the risk for each node is the node error weighted by the node probability.

nodesize

an n-element vector sizes of the sizes of the nodes in tree, where n is the number of nodes. the size of a node is defined as the number of observations from the data used to create the tree that satisfy the conditions for the node.

numnodes

the number of nodes n in tree.

parent

an n-element vector p containing the number of the parent node for each node in tree, where n is the number of nodes. the parent of the root node is 0.

predictornames

a cell array of names for the predictor variables, in the order in which they appear in x.

prunealpha

numeric vector with one element per pruning level. if the pruning level ranges from 0 to m, then prunealpha has m 1 elements sorted in ascending order. prunealpha(1) is for pruning level 0 (no pruning), prunealpha(2) is for pruning level 1, and so on.

prunelist

an n-element numeric vector with the pruning levels in each node of tree, where n is the number of nodes. the pruning levels range from 0 (no pruning) to m, where m is the distance between the deepest leaf and the root node.

responsename

name of the response variable y, a character vector.

responsetransform

function handle for transforming the raw response values (mean squared error). the function handle must accept a matrix of response values and return a matrix of the same size. the default 'none' means @(x)x, or no transformation.

add or change a responsetransform function using dot notation:

ctree.responsetransform = @function

surrogatecutcategories

an n-element cell array of the categories used for surrogate splits in tree, where n is the number of nodes in tree. for each node k, surrogatecutcategories{k} is a cell array. the length of surrogatecutcategories{k} is equal to the number of surrogate predictors found at this node. every element of surrogatecutcategories{k} is either an empty character vector for a continuous surrogate predictor, or is a two-element cell array with categories for a categorical surrogate predictor. the first element of this two-element cell array lists categories assigned to the left child by this surrogate split, and the second element of this two-element cell array lists categories assigned to the right child by this surrogate split. the order of the surrogate split variables at each node is matched to the order of variables in surrogatecutpredictor. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatecutcategories contains an empty cell.

surrogatecutflip

an n-element cell array of the numeric cut assignments used for surrogate splits in tree, where n is the number of nodes in tree. for each node k, surrogatecutflip{k} is a numeric vector. the length of surrogatecutflip{k} is equal to the number of surrogate predictors found at this node. every element of surrogatecutflip{k} is either zero for a categorical surrogate predictor, or a numeric cut assignment for a continuous surrogate predictor. the numeric cut assignment can be either –1 or 1. for every surrogate split with a numeric cut c based on a continuous predictor variable z, the left child is chosen if z<c and the cut assignment for this surrogate split is 1, or if zc and the cut assignment for this surrogate split is –1. similarly, the right child is chosen if zc and the cut assignment for this surrogate split is 1, or if z<c and the cut assignment for this surrogate split is –1. the order of the surrogate split variables at each node is matched to the order of variables in surrogatecutpredictor. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatecutflip contains an empty array.

surrogatecutpoint

an n-element cell array of the numeric values used for surrogate splits in tree, where n is the number of nodes in tree. for each node k, surrogatecutpoint{k} is a numeric vector. the length of surrogatecutpoint{k} is equal to the number of surrogate predictors found at this node. every element of surrogatecutpoint{k} is either nan for a categorical surrogate predictor, or a numeric cut for a continuous surrogate predictor. for every surrogate split with a numeric cut c based on a continuous predictor variable z, the left child is chosen if z<c and surrogatecutflip for this surrogate split is 1, or if zc and surrogatecutflip for this surrogate split is –1. similarly, the right child is chosen if zc and surrogatecutflip for this surrogate split is 1, or if z<c and surrogatecutflip for this surrogate split is –1. the order of the surrogate split variables at each node is matched to the order of variables returned by surrogatecutvar. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatecutpoint contains an empty cell.

surrogatecuttype

an n-element cell array indicating types of surrogate splits at each node in tree, where n is the number of nodes in tree. for each node k, surrogatecuttype{k} is a cell array with the types of the surrogate split variables at this node. the variables are sorted by the predictive measure of association with the optimal predictor in the descending order, and only variables with the positive predictive measure are included. the order of the surrogate split variables at each node is matched to the order of variables in surrogatecutpredictor. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatecuttype contains an empty cell. a surrogate split type can be either 'continuous' if the cut is defined in the form z<v for a variable z and cut point v or 'categorical' if the cut is defined by whether z takes a value in a set of categories.

surrogatecutpredictor

an n-element cell array of the names of the variables used for surrogate splits in each node in tree, where n is the number of nodes in tree. every element of surrogatecutpredictor is a cell array with the names of the surrogate split variables at this node. the variables are sorted by the predictive measure of association with the optimal predictor in the descending order, and only variables with the positive predictive measure are included. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatecutpredictor contains an empty cell.

surrogatepredictorassociation

an n-element cell array of the predictive measures of association for surrogate splits in tree, where n is the number of nodes in tree. for each node k, surrogatepredictorassociation{k} is a numeric vector. the length of surrogatepredictorassociation{k} is equal to the number of surrogate predictors found at this node. every element of surrogatepredictorassociation{k} gives the predictive measure of association between the optimal split and this surrogate split. the order of the surrogate split variables at each node is the order of variables in surrogatecutpredictor. the optimal-split variable at this node does not appear. for nonbranch (leaf) nodes, surrogatepredictorassociation contains an empty cell.

object functions

gather properties of statistics and machine learning toolbox object from gpu
limelocal interpretable model-agnostic explanations (lime)
regression error
retrieve variable range of decision tree node
partialdependencecompute partial dependence
plotpartialdependencecreate partial dependence plot (pdp) and individual conditional expectation (ice) plots
predict responses using regression tree
estimates of predictor importance for regression tree
shapleyshapley values
mean predictive measure of association for surrogate splits in regression tree
updateupdate model parameters for code generation
view regression tree

copy semantics

value. to learn how value classes affect copy operations, see .

examples

load the sample data.

load carsmall

construct a regression tree for the sample data.

tree = fitrtree([weight, cylinders],mpg,...
    'minparentsize',20,...
    'predictornames',{'w','c'});

make a compact version of the tree.

ctree = compact(tree);

compare the size of the compact tree to that of the full tree.

t = whos('tree'); % t.bytes = size of tree in bytes
c = whos('ctree'); % c.bytes = size of ctree in bytes
[c.bytes t.bytes]
ans = 1×2
        4311        7558

the compact tree is smaller than the full tree.

extended capabilities

version history

introduced in r2011a

网站地图