prune

Class: classregtree

Syntax

t2 = prune(t1,'level',level)
t2 = prune(t1,'nodes',nodes)
t2 = prune(t1)

Description

t2 = prune(t1,'level',level) takes a decision tree t1 and a pruning level level, and returns the decision tree t2 pruned to that level. If level is 0, there is no pruning. Trees are pruned based on an optimal pruning scheme that first prunes branches giving less improvement in error cost.

t2 = prune(t1,'nodes',nodes) prunes the nodes listed in the nodes vector from the tree. Any t1 branch nodes listed in nodes become leaf nodes in t2, unless their parent nodes are also pruned. Use view to display the node numbers for any node you select.

t2 = prune(t1) returns the decision tree t2 that is the full, unpruned t1, but with optimal pruning information added. This is useful only if t1 is created by pruning another tree, or by using the classregtree function with the 'prune' parameter set to 'off'. If you plan to prune a tree multiple times along the optimal pruning sequence, it is more efficient to create the optimal pruning sequence first.

Pruning is the process of reducing a tree by turning some branch nodes into leaf nodes and removing the leaf nodes under the original branch.

Examples

expand all

Prune a Decision Tree

Display the full tree for Fisher's iris data:

load fisheriris;
t1 = classregtree(meas,species,...
                  'names',{'SL' 'SW' 'PL' 'PW'},...
                  'minparent',5)
view(t1)
t1 = 

Decision tree for classification
 1  if PL<2.45 then node 2 elseif PL>=2.45 then node 3 else setosa
 2  class = setosa
 3  if PW<1.75 then node 4 elseif PW>=1.75 then node 5 else versicolor
 4  if PL<4.95 then node 6 elseif PL>=4.95 then node 7 else versicolor
 5  class = virginica
 6  if PW<1.65 then node 8 elseif PW>=1.65 then node 9 else versicolor
 7  if PW<1.55 then node 10 elseif PW>=1.55 then node 11 else virginica
 8  class = versicolor
 9  class = virginica
10  class = virginica
11  class = versicolor

Display the next largest tree from the optimal pruning sequence:

t2 = prune(t1,'level',1)
view(t2)
t2 = 

Decision tree for classification
1  if PL<2.45 then node 2 elseif PL>=2.45 then node 3 else setosa
2  class = setosa
3  if PW<1.75 then node 4 elseif PW>=1.75 then node 5 else versicolor
4  if PL<4.95 then node 6 elseif PL>=4.95 then node 7 else versicolor
5  class = virginica
6  class = versicolor
7  class = virginica

References

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

See Also

| |

Was this topic helpful?