CompactTreeBagger
statistics: CompactTreeBagger
Compact ensemble of bagged decision trees
A CompactTreeBagger object carries the trees a TreeBagger
ensemble grew and what prediction needs, but not the observations it was
fitted on, and so none of the out-of-bag information. It predicts new
data identically to the ensemble it came from.
Create one with the compact method of a TreeBagger object.
Two compact ensembles fitted on the same classes are joined with
combine.
See also: TreeBagger, TreeBagger.compact, CompactClassificationTree, CompactRegressionTree
Source Code: CompactTreeBagger
The CompactTreeBagger class contains the following properties:
'classification' or 'regression'. This property is
read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A nonnegative integer, the number of trees in the ensemble. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A column cell array holding one CompactClassificationTree or
CompactRegressionTree object per tree. This property is
read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
The classes of a classification ensemble, in the type of the response it was fitted on and in the order its scores are laid out. Empty for a regression ensemble. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
For classification, the class of greatest prior probability, in the
type of the class names, or the missing label of that type after
setDefaultYfit with ''. For regression, the weighted
mean of the training response unless set otherwise. This property is
read-only; change it with setDefaultYfit.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A cell array of character vectors naming the columns of the predictor data. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A row vector with one element per predictor, the mean over the trees
of each tree’s predictorImportance. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A row vector with one element per predictor, the sum over the trees of the share of each tree’s branch nodes that split on the predictor. A tree without branch nodes adds nothing. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
A square matrix with one row and one column per predictor. The trees grow no surrogate splits, so it is the identity matrix. This property is read-only.
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
The CompactTreeBagger class offers the following public methods:
CompactTreeBagger: label = predict (obj, X)
CompactTreeBagger: [label, scores] = predict (…)
CompactTreeBagger: [label, scores, stdevs] = predict (…)
CompactTreeBagger: [Yfit, stdevs] = predict (…)
CompactTreeBagger: … = predict (…, name, value)
For a classification ensemble, label holds the predicted class of
each row of X, in the type of ClassNames. scores is
an NxK matrix, the weighted average over the trees of the class
probability each tree gives, and stdevs holds their standard
deviations over the trees. The label is the class of highest score,
whatever cost matrix the trees were grown with, as MATLAB documents.
For a regression ensemble, Yfit is the weighted average of the trees’ predictions and stdevs their standard deviation.
The standard deviations are population deviations, taken over the
trees that answer for the observation with their weights. An
observation no tree may answer for is given DefaultYfit, with
the prior as its scores and NaN as its deviations.
Name-Value arguments:
| Name | Value | |
|---|---|---|
'Trees' | 'all' (default) or a vector of
indices of the trees to use. | |
'TreeWeights' | A nonnegative vector with one weight per tree used. The default weighs them equally. | |
'UseInstanceForTree' | An NxNumTrees logical matrix saying which tree may answer for which observation. The default lets every tree answer for every observation. |
MATLAB returns the labels as a cell array of character vectors whatever
the type of the response; they are returned here in the type of
ClassNames, as by every other classifier in this package.
See also: CompactTreeBagger, CompactTreeBagger.error, TreeBagger.predict
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: err = error (obj, X, Y)
CompactTreeBagger: err = error (…, name, value)
For a classification ensemble err is the weighted share of the rows of X whose predicted class differs from Y; for a regression ensemble it is the weighted mean squared error. By default err is a column with one element per tree, the error of the first tree, then of the first two, and so on.
An observation no tree may answer for is predicted as
DefaultYfit and counted; when DefaultYfit is the missing
label it has no prediction and is left out.
Name-Value arguments:
| Name | Value | |
|---|---|---|
'Mode' | 'cumulative' (default),
'individual' for the error of each tree on its own, or
'ensemble' for a single error over every tree used. | |
'Trees' | 'all' (default) or a vector of
indices of the trees to use, in the order they are accumulated. | |
'TreeWeights' | A nonnegative vector with one
weight per tree used. It may not be given in 'individual' mode. | |
'UseInstanceForTree' | An NxNumTrees logical matrix saying which tree may answer for which observation. | |
'Weights' | A nonnegative vector with one weight per observation. The default is uniform. |
See also: CompactTreeBagger, CompactTreeBagger.predict, CompactTreeBagger.meanMargin, TreeBagger.oobError
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: m = margin (obj, X, Y)
CompactTreeBagger: m = margin (…, name, value)
The margin is the score of the true class less the highest score among
the other classes. By default m has one row per observation and
one column per tree, the margin of the first tree, then of the first
two, and so on. An observation left without a prediction, as described
under CompactTreeBagger.error, has a NaN margin.
'Mode', 'Trees', 'TreeWeights' and
'UseInstanceForTree' are taken as by
CompactTreeBagger.error. A regression ensemble has no margins.
See also: CompactTreeBagger, CompactTreeBagger.meanMargin, CompactTreeBagger.error
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: mm = meanMargin (obj, X, Y)
CompactTreeBagger: mm = meanMargin (…, name, value)
mm is the weighted mean over the observations of the margins
CompactTreeBagger.margin returns, a row with one element per
tree by default. The Name-Value arguments are those of
CompactTreeBagger.error, 'Weights' included.
See also: CompactTreeBagger, CompactTreeBagger.margin
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: C = combine (C1, C2)
C holds the trees of C1 followed by those of C2. The
two must be of the same type and, for classification, have the same
class names and the same default scores. C keeps the
DefaultYfit of C1.
See also: CompactTreeBagger, TreeBagger.append
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: C = setDefaultYfit (obj, Yfit)
For a classification ensemble Yfit is 'MostPopular', the
class of greatest prior probability, or '', the missing label,
which leaves such an observation without a prediction and out of the
error and the mean margin. A logical response has no missing label.
For a regression ensemble Yfit is a numeric scalar.
See also: CompactTreeBagger, CompactTreeBagger.predict
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: prox = proximity (obj, X)
prox is a symmetric NxN matrix, N being the number of rows of X, whose element (i,j) is the share of the trees that bring observations i and j to the same leaf. Its diagonal holds ones.
See also: CompactTreeBagger, CompactTreeBagger.outlierMeasure, CompactTreeBagger.mdsprox, TreeBagger.fillprox
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: out = outlierMeasure (obj, X)
CompactTreeBagger: out = outlierMeasure (…, name, value)
The raw measure of an observation is the size of its class divided by the sum of its squared proximities to the observations of the class, itself included, all the observations forming one class when no labels are given. out is a column holding, for each observation, the absolute deviation of its raw measure from the median of its class, divided by the median absolute deviation of the class. A large value marks an observation that the trees seldom group with the rest of its class. As in MATLAB, a class whose median absolute deviation is zero gives the raw measures themselves, and a class of one or two observations gives zeros.
Name-Value arguments:
| Name | Value | |
|---|---|---|
'Data' | 'predictors' (default), for
X holding predictor data, or 'proximity', for X
holding a proximity matrix such as proximity returns. | |
'Labels' | The class label of each observation,
each one of ClassNames. Classification only. |
See also: CompactTreeBagger, CompactTreeBagger.proximity, TreeBagger.OutlierMeasure
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
CompactTreeBagger: [S, E] = mdsprox (obj, X)
CompactTreeBagger: [S, E] = mdsprox (…, name, value)
Applies classical multidimensional scaling, as cmdscale does, to
the distances 1 - prox, prox being the proximity
matrix of the rows of X. S holds the scaled coordinates,
one column per positive eigenvalue, and E the eigenvalues.
Name-Value arguments:
| Name | Value | |
|---|---|---|
'Data' | 'predictors' (default) or
'proximity', as for outlierMeasure. | |
'Colors' | A character vector with one color letter per class. When given, the scaled coordinates are drawn as overlaid scatter plots, one per class, and a class beyond the number of letters is not drawn. | |
'Labels' | The class label of each observation,
each one of ClassNames. Classification only. Without labels
every observation is drawn in the first color. | |
'MDSCoordinates' | Two or three indices of the
columns of S to draw. The default is [1, 2]. They must
not exceed the number of columns of S even when nothing is drawn,
as in MATLAB, whose documentation says otherwise. |
See also: CompactTreeBagger, CompactTreeBagger.proximity, cmdscale, TreeBagger.mdsprox
Compact a random forest and classify new flowers with it. The compact ensemble keeps the trees but not the training data.
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}
load fisheriris rng (42); C = compact (TreeBagger (30, meas, species)); label = predict (C, [5.0, 3.4, 1.5, 0.2; 6.7, 3.0, 5.2, 2.3])
label =
2x1 cell array
{'setosa' }
{'virginica'}