Documentation |
ClassificationTree.fit will be removed in a future release. Use fitctree instead.
tree = ClassificationTree.fit(x,y)
tree = ClassificationTree.fit(x,y,Name,Value)
tree = ClassificationTree.fit(x,y) returns a classification tree based on the input variables (also known as predictors, features, or attributes) x and output (response) y. tree is a binary tree, where each branching node is split based on the values of a column of x.
tree = ClassificationTree.fit(x,y,Name,Value) fits a tree with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.
Note that using the 'CrossVal', 'KFold', 'Holdout', 'Leaveout', or 'CVPartition' options results in a tree of class ClassificationPartitionedModel. You cannot use a partitioned tree for prediction, so this kind of tree does not have a predict method.
Otherwise, tree is of class ClassificationTree, and you can use the predict method to make predictions.
ClassificationTree splits nodes based on either impurity or node error.
Impurity means one of several things, depending on your choice of the SplitCriterion name-value pair argument:
Gini's Diversity Index (gdi) — The Gini index of a node is
$$1-{\displaystyle \sum _{i}{p}^{2}(i)},$$
where the sum is over the classes i at the node, and p(i) is the observed fraction of classes with class i that reach the node. A node with just one class (a pure node) has Gini index 0; otherwise the Gini index is positive. So the Gini index is a measure of node impurity.
Deviance ('deviance') — With p(i) defined the same as for the Gini index, the deviance of a node is
$$-{\displaystyle \sum _{i}p(i)\mathrm{log}p(i)}.$$
A pure node has deviance 0; otherwise, the deviance is positive.
Twoing rule ('twoing') — Twoing is not a purity measure of a node, but is a different measure for deciding how to split a node. Let L(i) denote the fraction of members of class i in the left child node after a split, and R(i) denote the fraction of members of class i in the right child node after a split. Choose the split criterion to maximize
$$P(L)P(R){\left({\displaystyle \sum _{i}\left|L(i)-R(i)\right|}\right)}^{2},$$
where P(L) and P(R) are the fractions of observations that split to the left and right respectively. If the expression is large, the split made each child node purer. Similarly, if the expression is small, the split made each child node similar to each other, and hence similar to the parent node, and so the split did not increase node purity.
Node error — The node error is the fraction of misclassified classes at a node. If j is the class with the largest number of training samples at a node, the node error is
1 – p(j).
[1] Coppersmith, D., S. J. Hong, and J. R. M. Hosking. "Partitioning Nominal Attributes in Decision Trees." Data Mining and Knowledge Discovery, Vol. 3, 1999, pp. 197–217.
[2] Breiman, L., J. Friedman, R. Olshen, and C. Stone. Classification and Regression Trees. Boca Raton, FL: CRC Press, 1984.