| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
Note treefit will be removed in a future release. Use classregtree instead. |
t = treefit(X,y)
t = treefit(X,y,param1,val1,param2,val2,...)
Note This function is superseded by the classregtree constructor of the classregtree class and is maintained only for backwards compatibility. It returns objects t in the classregtree class. |
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.
| Parameter | Value |
|---|---|
| 'catidx' | Vector of indices of the columns of X. treefit treats these columns as unordered categorical values. |
| 'method' | Either 'classification' (default if y is text) or 'regression' (default if y is numeric). |
| 'splitmin' | A number n such that impure nodes must have n or more observations to be split (default 10). |
| 'prune' | '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.
| Parameter | Value |
|---|---|
| 'cost' | 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: S.group containing the group names (see Grouped Data), and S.cost containing a matrix of cost values. |
| 'splitcriterion' | Criterion for choosing a split: either 'gdi' (default) for Gini's diversity index, 'twoing' for the twoing rule, or '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 S with two fields: S.group 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.
![]() | treedisp | treeprune | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |