B = TreeBagger(NumTrees,Tbl,ResponseVarName)
B = TreeBagger(NumTrees,Tbl,Formula)
B = TreeBagger(NumTrees,Tbl,Y)
B = TreeBagger(NumTrees,X,Y)
B = TreeBagger(NumTrees,X,Y,Name,Value
)
B = TreeBagger(NumTrees,Tbl,ResponseVarName)
creates
an ensemble for predicting the responses stored in ResponseVarName
as
a function of the predictors in the table Tbl
,
where ResponseVarName
is the name of a variable
in Tbl
. By default TreeBagger
builds
an ensemble of classification trees. The function can build an ensemble
of regression trees by setting the optional input argument 'Method'
to 'regression'
.
B = TreeBagger(NumTrees,Tbl,Formula)
creates
an ensemble B
of NumTrees
using
the formula string Formula
to specify the response
and predictor variables in Tbl
. Specify Formula
using
Wilkinson notation. For more information, see Wilkinson Notation.
B = TreeBagger(NumTrees,Tbl,Y)
creates
an ensemble B
of NumTrees
decision
trees for predicting responses in vector Y
as a
function of the predictors stored in the table Tbl
.
Y
is an array of response data. Elements
of Y
correspond to the rows of Tbl
or X
.
For classification, Y
is the set of true class
labels. Labels can be any grouping variable,
that is, a numeric or logical vector, character matrix, cell vector
of strings, or categorical vector. TreeBagger
converts
labels to a cell array of strings for classification. For regression, Y
is
a numeric vector.
B = TreeBagger(NumTrees,X,Y)
creates an
ensemble B
of NumTrees
decision
trees for predicting response Y
as a function of
predictors in the numeric matrix of training data, X
.
Each row in X
represents an observation and each
column represents a predictor or feature.
B = TreeBagger(NumTrees,X,Y,
specifies
optional parameter namevalue pairs: Name,Value
)
'InBagFraction'  Fraction of input data to sample with replacement from the input data for growing each new tree. Default value is 1. 
'Cost'  Square matrix Alternatively,
The default value is If 
 'on' to sample with replacement or 'off' to
sample without replacement. If you sample without replacement, you
need to set 'InBagFraction' to a value less than
one. Default is 'on' . 
'OOBPrediction'  'on' to store info on what observations
are out of bag for each tree. This info can be used by oobPrediction to
compute the predicted class probabilities for each tree in the ensemble.
Default is 'off' . 
'OOBPredictorImportance'  'on' to store outofbag estimates of feature
importance in the ensemble. Default is 'off' . Specifying 'on' also
sets the 'OOBPrediction' value to 'on' . 
'Method'  Either 'classification' or 'regression' .
Regression requires a numeric Y . 
'NumPredictorsToSample'  Number of variables to select at random for each decision split.
Default is the square root of the number of variables for classification
and one third of the number of variables for regression. Valid values
are 'all' or a positive integer. Setting this argument
to any valid value but 'all' invokes Breiman's
'random forest' algorithm. 
'NumPrint'  Number of training cycles (grown trees) after which TreeBagger displays
a diagnostic message showing training progress. Default is no diagnostic
messages. 
'MinLeafSize'  Minimum number of observations per tree leaf. Default is 1 for classification and 5 for regression. 
'Options'  A structure that specifies options that govern the computation
when growing the ensemble of decision trees. One option requests that
the computation of decision trees on multiple bootstrap replicates
uses multiple processors, if the Parallel Computing Toolbox™ is
available. Two options specify the random number streams to use in
selecting bootstrap replicates. You can create this argument with
a call to statset . You can retrieve values of the
individual fields with a call to statget .
Applicable statset parameters
are:

'Prior'  Prior probabilities for each class. Specify as one of:
If you set values for both If 
'CategoricalPredictors'  Categorical predictors list, specified as the commaseparated
pair consisting of

In addition to the optional
arguments above, this method accepts all optional fitctree
and fitrtree
arguments
with the exception of 'MinParent'
. Refer to the
documentation for fitctree
and fitrtree
for more detail.
TreeBagger
generates inbag samples by oversampling
classes with large misclassification costs and undersampling classes
with small misclassification costs. Consequently, outofbag samples
have fewer observations from classes with large misclassification
costs and more observations from classes with small misclassification
costs. If you train a classification ensemble using a small data set
and a highly skewed cost matrix, then the number of outofbag observations
per class might be very low. Therefore, the estimated outofbag error
might have a large variance and might be difficult to interpret. The
same phenomenon can occur for classes with large prior probabilities.
Avoid large estimated outofbag error variances by setting a more balanced misclassification cost matrix or a less skewed prior probability vector.
The Trees
property of B
stores
a cell vector of B.NumTrees
CompactClassificationTree
or CompactRegressionTree
model
objects. For a textual or graphical display of tree t
in
the cell vector, enter
view(B.Trees{t})