Statistics Toolbox | ![]() ![]() |
Compute fitted value for decision tree applied to data
Syntax
YFIT = treeval(T,X) YFIT = treeval(T,X,subtrees) [YFIT,NODE] = treeval(...) [YFIT,NODE,CNAME] = treeval(...)
Description
YFIT = treeval(T,X)
takes a classification or regression tree T
as produced by the treefit
function, and a matrix X
of predictor values, and produces a vector YFIT
of predicted response values. For a regression tree, YFIT(j)
is the fitted response value for a point having the predictor values X(j,:)
. For a classification tree, YFIT(j)
is the class number into which the tree would assign the point with data X(j,:)
. To convert the number into a class name, use the third output argument, cname
(below).
YFIT = treeval(T,X,subtrees)
takes an additional vector subtrees
of pruning levels, with 0
representing the full, unpruned tree. T
must include a pruning sequence as created by the treefit
or prunetree
function. If subtree
has k
elements and X
has n
rows, then the output YFIT
is an n
-by-k
matrix, with the j
th column containing the fitted values produced by the subtrees(j)
subtree. subtrees
must be sorted in ascending order.
[YFIT,NODE] = treeval(...)
also returns an array NODE
of the same size as YFIT
containing the node number assigned to each row of X
. The treedisp
function can display the node numbers for any node you select.
[YFIT,NODE,CNAME] = treeval(...)
is valid only for classification trees. It retuns a cell array CNAME
containing the predicted class names.
Examples
Find the predicted classifications for Fisher's iris data.
load fisheriris; t = treefit(meas,species); % Create decision tree sfit = treeval(t,meas); % Find assigned class numbers sfit = t.classname(sfit); % Get class names mean(strcmp(sfit,species)) % Compute proportion correctly % classified ans = 0.9800
See Also
![]() | treetest | trimmean | ![]() |