This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Predicted responses

treeval will be removed in a future release. Use fitctree or fitrtree to grow a tree. Then use predict (ClassificationTree) or predict (RegressionTree) instead of treeval.


yfit = treeval(t,X)
yfit = treeval(t,X,subtrees)
[yfit,node] = treeval(...)
[yfit,node,cname] = treeval(...)


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(i) is the fitted response value for a point having the predictor values X(i,:). For a classification tree, yfit(i) is the class number into which the tree would assign the point with data X(i,:). To convert the number into a class name, use the third output argument, cname (described 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, the output yfit is an n-by-k matrix, with the jth 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 returns a cell array cname containing the predicted class names.


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))  % Proportion in correct class
ans =


[1] Breiman, L., J. Friedman, R. Olshen, and C. Stone. Classification and Regression Trees. Boca Raton, FL: CRC Press, 1984.

Introduced before R2006a

Was this topic helpful?