Categories &

Functions List

Class Definition: CompactRegressionTree

statistics: CompactRegressionTree

Compact binary decision tree for regression

A CompactRegressionTree object carries the tree a RegressionTree model grew and everything predict needs, but not the observations it was fitted on. It answers new data identically to the model it came from, and is far smaller to keep or to ship.

Create one with the compact method of a RegressionTree object. Because it holds no training data, it has no resub methods and cannot be cross-validated, and it cannot be pruned: the pruning sequence is reported but taking a subtree out of it rewrites the node table, which is work for the model that still has its data.

See also: RegressionTree, fitrtree

Source Code: CompactRegressionTree

The CompactRegressionTree class contains the following properties:

A positive integer, the number of nodes the tree holds, branch nodes and leaves together. Nodes are numbered as they are created, so a parent always carries a lower number than either of its children. This property is read-only.

A NumNodesx2 matrix naming the left and the right child of each node. A leaf carries a zero in both columns. This property is read-only.

A column vector naming the parent of each node. The root carries a zero. This property is read-only.

A logical column vector, true for each node that carries a split and false for each leaf. This property is read-only.

A cell array of character vectors with one entry per node, holding the name of the predictor the node splits on and an empty character vector at a leaf. This property is read-only.

A column vector holding, for each node, the column of X the node splits on, and zero at a leaf. This property is read-only.

A column vector holding, for each node, the value the split compares the predictor against: an observation goes left when its value is less than the cut point and right otherwise. A leaf and a categorical cut carry NaN. This property is read-only.

A cell array of character vectors holding 'continuous' at a branch node that cuts a numeric predictor at a point, 'categorical' at one that splits a set of levels, and an empty character vector at a leaf. This property is read-only.

A NumNodesx2 cell array holding, for a node that cuts a categorical predictor, the levels sent left and the levels sent right. Every other entry is empty. This property is read-only.

A Nx2 cell array with one row per categorical split, in node order, holding the levels sent left and the levels sent right. It is empty when no split is categorical. This property is read-only.

A column vector holding how many training observations reached each node. A row missing the predictor its node cuts on is counted at that node and at none below it, so a parent’s size is not in general the sum of its children’s. This property is read-only.

A column vector holding, for each node, the weighted mean of the response over the observations that reached it. It is what predict answers for a row that comes to rest there. This property is read-only.

A column vector holding, for each node, the weighted mean squared error of the response about the node’s mean. This property is read-only.

A column vector holding, for each node, the total weight of the observations that reached it, the weights being those in W. The root carries one. This property is read-only.

A column vector holding, for each node, its mean squared error weighted by the probability of reaching it, which is the squared error the node contributes to the whole tree. This property is read-only.

A column vector holding, for each branch node, the level of the cost complexity sequence at which it stops being a branch node, and zero at a leaf. Pruning the tree to level L turns every node whose level is between one and L into a leaf. It is empty when neither 'Prune' nor 'MergeLeaves' was asked for, since no sequence was then estimated. This property is read-only.

A column vector with one element per level of the pruning sequence, the first of which is zero and stands for the unpruned tree. Level L is the smallest subtree that is optimal for every complexity parameter from PruneAlpha(L+1) up to the next one. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

Surrogate splits are not implemented, so this is always empty. This property is read-only.

A cell array of character vectors with one name per column of X. This property is read-only.

A character vector naming the response. This property is read-only.

A row vector of column indices into X, naming the predictors treated as categorical, empty when none is. This property is read-only.

A cell array of character vectors. It differs from PredictorNames only when a categorical predictor has been expanded into one column per level, which this class does not do, so the two are always equal. This property is read-only.

A character vector naming the function predict applies to the response it predicts before returning it, or a function handle taking and returning an array of the same size. The default is 'none'.

The CompactRegressionTree class offers the following public methods:

CompactRegressionTree: yFit = predict (obj, XC)
CompactRegressionTree: [yFit, node] = predict (…)

yFit = predict (obj, XC) sends each row of XC down the tree and returns the mean response of the node it comes to rest at, after ResponseTransform. XC must have as many columns as the predictor data the model was fitted on.

[yFit, node] = predict (…) also returns the number of the node each row landed in.

A row missing the predictor a node cuts on is stopped at that node and takes its answer, rather than being sent down a branch on evidence the row does not carry.

See also: CompactRegressionTree, fitrtree

CompactRegressionTree: imp = predictorImportance (obj)

imp = predictorImportance (obj) returns a row vector with one element per predictor, holding the total drop in risk the splits on that predictor bring about, divided by the number of branch nodes. A predictor the tree never splits on scores zero.

The drop at a branch node is its NodeRisk less the risk of its two children and less what it holds back, so a predictor that is chosen often, high up, and on nodes it separates well, scores highest. The numbers are comparable between predictors of one tree and not between trees.

See also: CompactRegressionTree, fitrtree, CompactRegressionTree.NodeRisk

CompactRegressionTree: r = nodeVariableRange (obj, node)

r = nodeVariableRange (obj, node) returns a structure with one field per predictor the path from the root to node cuts on, holding the two-element range of values that reach the node, or for a categorical predictor the levels that reach it. A predictor the path never cuts on is unconstrained and is left out, so the root gives a structure with no fields.

See also: CompactRegressionTree, fitrtree

CompactRegressionTree: view (obj)

view (obj) prints one line per node: a branch node names the predictor it cuts on, the cut point, and the node each side leads to, and a leaf names the response it fits. A branch node’s line ends with the response it would fit itself, which is the answer an observation missing that predictor gets.

See also: CompactRegressionTree, fitrtree

CompactRegressionTree: L = loss (obj, X, Y)
CompactRegressionTree: L = loss (…, name, value)

L = loss (obj, X, Y) returns the weighted mean squared error of the response the model predicts for X against the observed response Y. A row whose response is missing is dropped, as it is when fitting.

L = loss (…, name, value) takes the following options.

NameValue
'LossFun''mse', the default, or a function handle taking the true response, the predicted response and the weights, and returning a numeric scalar.
'Weights'A numeric vector of observation weights, one per row of X, normalized to sum to one before it is applied.

See also: CompactRegressionTree, fitrtree, CompactRegressionTree.predict

CompactRegressionTree: savemodel (obj, filename)

savemodel (obj, filename) saves each property of a CompactRegressionTree object into an Octave binary file, the name of which is specified in filename, along with an extra variable, which defines the type of regression object these variables constitute. Use loadmodel in order to load a regression object into Octave’s workspace.

See also: loadmodel, fitrtree, RegressionTree