CompactClassificationTree
statistics: CompactClassificationTree
Compact binary decision tree for classification
A CompactClassificationTree object carries the tree a
ClassificationTree model grew and everything predict needs,
but not the observations it was fitted on. It classifies 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 ClassificationTree
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: ClassificationTree, fitctree
Source Code: CompactClassificationTree
The CompactClassificationTree 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 cell array of character vectors naming, for each node, the class of least expected misclassification cost given the node’s class probabilities. Under the default cost that is simply the most probable class, with the first of the class names kept on a tie. This property is read-only.
A column vector holding, for each node, the expected misclassification cost of the class the node is assigned. Under the default cost that is the probability that the node’s class is wrong, one less the largest class probability. 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 the model it came from was fitted with. The root carries one. This property is read-only.
A column vector holding, for each node, the impurity of the node
weighted by the probability of reaching it, measured by whichever of
'gdi' and 'deviance' the tree was grown under.
A non-default Cost enters here rather than through the class
probabilities: the weights are scaled class by class by the total cost
of misclassifying that class, and the impurity is measured on the
scaled distribution. This property is read-only.
A NumNodesxK matrix holding how many training observations of each class reached each node. These are counts and take no notice of the observation weights. This property is read-only.
A NumNodesxK matrix holding, for each node, the weight of each class among the observations that reached it, as a proportion of the node’s total weight. The root row is the prior. 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.
The distinct class labels, in the type the response was given in and sorted. 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 numeric row vector with one element per class, summing to one. It defaults to the weight each class carries in the training data, and may be reassigned after fitting.
Reassigning it re-derives every node statistic that depends on the
class weights, so ClassProbability, NodeProbability,
NodeClass, NodeError and NodeRisk all follow.
The shape of the tree does not, having been decided by the prior in
force when it was grown. MATLAB reports this property read-only on a
compact tree and refuses the assignment; it is settable here, as it is
on the package’s other compact classifiers.
A square numeric matrix with one row and column per class, where
Cost(i,j) is the cost of classifying an observation of class
i into class j. It defaults to 1 - eye (K) and may
be reassigned after fitting.
Reassigning it re-derives NodeClass, NodeError and
NodeRisk, and changes what predict answers. The shape
of the tree does not follow, having been decided by the cost in force
when it was grown. MATLAB reports this property read-only on a
compact tree and refuses the assignment; it is settable here, as it is
on the package’s other compact classifiers.
A character vector naming the function predict applies to the
class probabilities before returning them, or a function handle. The
default is 'none'.
The CompactClassificationTree class offers the following public methods:
CompactClassificationTree: label = predict (obj, XC)
CompactClassificationTree: [label, score] = predict (…)
CompactClassificationTree: [label, score, node] = predict (…)
CompactClassificationTree: [label, score, node, cnum] = predict (…)
label = predict (obj, XC) sends each row of
XC down the tree and returns the class of the node it comes to
rest at. XC must have as many columns as the predictor data the
model was fitted on.
[label, score] = predict (…) also returns
score, an NxK matrix holding the class probabilities of
the node each row landed in, after ScoreTransform.
[label, score, node] = predict (…) also
returns the number of the node each row landed in, and
[label, score, node, cnum] = predict
(…) the index of the predicted class into ClassNames.
The label is the class of least expected misclassification cost, which
under the default Cost is the most probable class of the node.
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: CompactClassificationTree, fitctree
CompactClassificationTree: 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, 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: CompactClassificationTree, fitctree, CompactClassificationTree.NodeRisk
CompactClassificationTree: 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: CompactClassificationTree, fitctree
CompactClassificationTree: 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 class it assigns. A branch node’s line ends
with the class it would assign itself, which is the answer an
observation missing that predictor gets.
See also: CompactClassificationTree, fitctree
CompactClassificationTree: m = margin (obj, X, Y)
m = margin (obj, X, Y) returns one
margin per observation: the score the model gives the observation’s
true class, less the largest score it gives any other class. A
positive margin means the observation is classified correctly, and a
larger one means it is classified more confidently.
See also: CompactClassificationTree, CompactClassificationTree.edge, CompactClassificationTree.loss, CompactClassificationTree.predict
CompactClassificationTree: e = edge (obj, X, Y)
CompactClassificationTree: e = edge (…, 'Weights', w)
e = edge (obj, X, Y) returns the
weighted mean of the margins, a single number summarising how
confidently the model classifies the data.
The weights are normalized within each class to that class’s prior before they are applied.
See also: CompactClassificationTree, CompactClassificationTree.margin, CompactClassificationTree.loss, CompactClassificationTree.predict
CompactClassificationTree: l = loss (obj, X, Y)
CompactClassificationTree: l = loss (…, name, value)
l = loss (obj, X, Y) returns the
minimum expected misclassification cost.
l = loss (…, name, value) takes the
following options.
| Name | Value |
|---|---|
'LossFun' | One of 'binodeviance',
'classifcost', 'classiferror', 'exponential',
'hinge', 'logit', 'mincost' (default) or
'quadratic'. |
'Weights' | A numeric vector of observation weights, one per row of X. |
See also: CompactClassificationTree, CompactClassificationTree.margin, CompactClassificationTree.edge, CompactClassificationTree.predict
CompactClassificationTree: savemodel (obj, filename)
savemodel (obj, filename) saves each property of a
CompactClassificationTree object into an Octave binary file, the name
of which is specified in filename, along with an extra variable,
which defines the type of classification object these variables
constitute. Use loadmodel in order to load a classification
object into Octave’s workspace.
See also: loadmodel, fitctree, ClassificationTree