main content

produce sequence of classification subtrees by pruning -凯发k8网页登录

class:

produce sequence of classification subtrees by pruning

syntax

tree1 = prune(tree)
tree1 = prune(tree,name,value)

description

tree1 = prune(tree) creates a copy of the classification tree tree with its optimal pruning sequence filled in.

tree1 = prune(tree,name,value) creates a pruned tree with additional options specified by one name,value pair argument. you can specify several name-value pair arguments in any order as name1,value1,…,namen,valuen.

input arguments

tree

a classification tree created with fitctree.

name-value arguments

specify optional pairs of arguments as name1=value1,...,namen=valuen, where name is the argument name and value is 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 enclose name in quotes.

alpha

a numeric scalar. prune prunes tree to the specified value of the pruning cost.

level

a numeric scalar from 0 (no pruning) to the largest pruning level of this tree max(tree.prunelist). prune returns the tree pruned to this level.

nodes

a numeric vector with elements from 1 to tree.numnodes. any tree branch nodes listed in nodes become leaf nodes in tree1, unless their parent nodes are also pruned.

output arguments

tree1

a classification tree.

examples

construct and display a full classification tree for fisher's iris data.

load fisheriris;
varnames = {'sl','sw','pl','pw'};
t1 = fitctree(meas,species,'minparentsize',5,'predictornames',varnames);
view(t1,'mode','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. one or more of the lines displays its values using only markers

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

t2 = prune(t1,'level',1);
view(t2,'mode','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. one or more of the lines displays its values using only markers

tips

  • tree1 = prune(tree) returns the decision tree tree1 that is the full, unpruned tree, but with optimal pruning information added. this is useful only if you created tree by pruning another tree, or by using the fitctree function 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

网站地图