treetrain
statistics: Mdl = treetrain (X, Y, W, opts)
Grow a binary decision tree by recursive partitioning.
Mdl = treetrain (X, Y, W, opts) grows a
tree on the NxP predictor matrix X and returns it as a structure
with one row per node. It is the fitting engine shared by
ClassificationTree and RegressionTree, and is not meant to be
called directly.
Y is an Nx1 vector of class indices in 1:K when fitting a
classifier and the response itself when fitting a regression. W is an
Nx1 vector of observation weights, already adjusted for any prior.
opts is a structure carrying NumClasses, MinParent,
MinLeaf, MaxSplits, SplitCriterion,
MergeLeaves and, for a regression, QEToler.
SplitCriterion is "gdi" or "deviance" for a
classifier and "mse" for a regression, and it is what selects
between the two.
NumVariablesToSample, when present, is the number of predictors
each node chooses its split from, drawn afresh at every node, and
Seed, an integer from 0 to 2^32-1, seeds that draw, so the
same seed grows the same tree. A node whose predictors hold no valid split
is a leaf. Without NumVariablesToSample every predictor is tried and
nothing is drawn.
CategoricalPredictors, when present, lists the columns of X
that hold levels rather than numbers, and such a column is split into two
sets of levels. A regression orders the levels by mean response and two
classes by the probability of the first class. More classes search every
partition when the node holds at most MaxNumCategories levels, 10
by default, and otherwise take MATLAB’s heuristics, as
AlgorithmForCategorical selects: "auto" (default),
"exact", "pullleft", "pca" or
"ovabyclass".
The returned structure holds Children, Parent,
CutPredictorIndex, CutPoint, CutCategories,
IsBranchNode, NodeSize, NodeWeight and
NumNodes, plus
ClassWeight and ClassCount for a classifier or
NodeMean and NodeError for a regression.
Nodes are numbered as they are created, so a parent always precedes its
children.
The cost complexity pruning sequence is not built here. A tree outlives
the data it was grown on, so the sequence is __treeprune__, which
takes a node table and the risk the caller measures by.
See also: treepredict
Source Code: treetrain