Main Content


Reduce size of classification tree model



ctree = compact(tree) returns a CompactClassificationTree version of the trained classification tree model tree.

You can predict classifications using the CompactClassificationTree model object ctree in the same way as when you use tree. However, because ctree does not contain training data, you cannot perform certain tasks, such as cross-validation.


collapse all

Compare the size of the classification tree for Fisher's iris data to the compact version of the tree.

load fisheriris
fulltree = fitctree(meas,species);
ctree = compact(fulltree);
b = whos('fulltree'); % b.bytes = size of fulltree
c = whos('ctree'); % c.bytes = size of ctree
[b.bytes c.bytes] % shows ctree uses half the memory
ans = 1×2

       11931        5266

Input Arguments

collapse all

Full classification tree model, specified as a ClassificationTree model object trained with fitctree.

Extended Capabilities

Version History

Introduced in R2011a