Main Content

修剪

Class:分类树

Produce sequence of classification subtrees by pruning

Syntax

tree1 = prune(tree)
tree1 = prune(tree,Name,Value)

Description

tree1=修剪(tree)creates a copy of the classification treetreewith its optimal pruning sequence filled in.

tree1=修剪(tree,Name,Value)creates a pruned tree with additional options specified by oneName,Valuepair argument. You can specify several name-value pair arguments in any order asName1,Value1,…,NameN,ValueN.

Input Arguments

tree

创建的分类树fitctree.

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Alpha

A numeric scalar.修剪修剪streeto the specified value of the pruning cost.

Level

A numeric scalar from0(no pruning) to the largest pruning level of this treemax(tree.PruneList).修剪returns the tree pruned to this level.

Nodes

A numeric vector with elements from1totree.NumNodes. Anytreebranch nodes listed innodesbecome leaf nodes intree1, unless their parent nodes are also pruned.

Output Arguments

tree1

A classification tree.

Examples

expand all

Construct and display a full classification tree for Fisher's iris data.

loadfisheriris; varnames = {'SL','SW','PL','PW'}; t1 = fitctree(meas,species,'MinParentSize',5,'PredictorNames',varnames); view(t1,“模式”,'graph');

Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 21 objects of type line, text.

Construct and display the next largest tree from the optimal pruning sequence.

t2 = prune(t1,'Level',1);查看(T2,“模式”,'graph');

Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 15 objects of type line, text.

Tips

  • tree1 = prune(tree)returns the decision treetree1that is the full, unprunedtree, but with optimal pruning information added. This is useful only if you createdtreeby pruning another tree, or by using thefitctreefunction with pruning set'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.

Extended Capabilities

See Also