Note:   treefit will be removed in a future release. Use fitctree or fitrtree instead.


t = treefit(X,y)
t = treefit(X,y,param1,val1,param2,val2,...)


t = treefit(X,y) creates a decision tree t for predicting response y as a function of predictors X. X is an n-by-m matrix of predictor values. y is either a vector of n response values (for regression), or a character array or cell array of strings containing n class names (for classification). Either way, t is a binary tree where each non-terminal node is split based on the values of a column of X.

t = treefit(X,y,param1,val1,param2,val2,...) specifies optional parameter name-value pairs. Valid parameter strings are:

The following table lists parameters available for all trees.


Vector of indices of the columns of X. treefit treats these columns as unordered categorical values.


Either 'classification' (default if y is text) or 'regression' (default if y is numeric).


A number n such that impure nodes must have n or more observations to be split (default 10).


'on' (default) to compute the full tree and a sequence of pruned subtrees, or 'off' for the full tree without pruning.

The following table lists parameters available for classification trees only.


p-by-p matrix C, where p is the number of distinct response values or class names in the input y. 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.) C can also be a structure S with two fields: containing the group names, and S.cost containing a matrix of cost values.


Criterion for choosing a split: either 'gdi' (default) for Gini's diversity index, 'twoing' for the twoing rule, or 'deviance' for maximum deviance reduction.


Prior probabilities for each class, specified as a vector (one value for each distinct group name) or as a structure S with two fields: containing the group names, and S.prob containing a vector of corresponding probabilities.


Create a classification tree for Fisher's iris data:

  load fisheriris;
  t = treefit(meas,species);
  treedisp(t,'names',{'SL' 'SW' 'PL' 'PW'});


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

See Also


Introduced before R2006a

Was this topic helpful?