| Statistics Toolbox™ | ![]() |
t = classregtree(X,y)
t = classregtree(X,y,param1,val1,param2,val2)
t = classregtree(X,y) creates a decision tree t for predicting the response y as a function of the predictors in the columns of X. X is an n-by-m matrix of predictor values. If y is a vector of n response values, classregtree performs regression. If y is a categorical variable, character array, or cell array of strings, classregtree performs classification. Either way, t is a binary tree where each branching node is split based on the values of a column of X. NaN values in X or y are taken as missing values, and observations with any missing values are not used in the fit.
t = classregtree(X,y,param1,val1,param2,val2) specifies optional parameter name/value pairs, as follows.
For all trees:
'categorical' — Vector of indices of the columns of X that are to be treated as unordered (nominal) categorical variables.
'method' — Either 'classification' (default if y is text or a categorical variable) or 'regression' (default if y is numeric).
'names' — A cell array of names for the predictor variables, in the order in which they appear in the X from which the tree was created.
'prune' — 'on' (default) to compute the full tree and the optimal sequence of pruned subtrees, or 'off' for the full tree without pruning.
'splitmin' — A number k such that impure nodes must have k or more observations to be split (default is 10).
For classification trees only:
'cost' — Square matrix C, where C(i,j) is the cost of classifying a point into class j if its true class is i. (The default has C(i,j) = 1 if i ~= j, and C(i,j) = 0 if i = j.) Alternatively, this value can be a structure with two fields:
group — Containing the group names as a categorical array, a character array, or cell array of strings
cost — Containing the cost matrix C
'splitcriterion' — Criterion for choosing a split. One of:
'gdi' — For Gini's diversity index (default)
'twoing' — For the twoing rule
'deviance' — For maximum deviance reduction
'priorprob' — Prior probabilities for each class, specified as a vector (one value for each distinct group name) or as a structure with two fields:
group — Containing the group names as a categorical array, a character array, or cell array of strings
prob — Containing a vector of corresponding probabilities
Create a classification tree for Fisher's iris data:
load fisheriris;
t = classregtree(meas,species,...
'names',{'SL' 'SW' 'PL' 'PW'})
t =
Decision tree for classification
1 if PL<2.45 then node 2 else node 3
2 class = setosa
3 if PW<1.75 then node 4 else node 5
4 if PL<4.95 then node 6 else node 7
5 class = virginica
6 if PW<1.65 then node 8 else node 9
7 class = virginica
8 class = versicolor
9 class = virginica
view(t)

[1] Breiman, L., J. Friedman, R. Olshen, and C. Stone. Classification and Regression Trees. Boca Raton, FL: CRC Press, 1984.
![]() | classprob | cluster | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |