Documentation

Syntax

view(tree)
view(tree,Name,Value)

Description

view(tree) returns a text description of tree, a decision tree.

view(tree,Name,Value) describes tree with additional options specified by one or more Name,Value pair arguments.

Input Arguments

tree

A classification tree or compact classification tree created by fitctree or compact.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'Mode'

String describing the display of tree, either 'graph' or 'text'. 'graph' opens a user interface displaying tree, and containing controls for querying the tree. 'text' sends output to the Command Window describing tree.

Default: 'text'

Tip

To view tree t from an ensemble of trees, enter one of these lines of code

view(Ens.Trained{t})
view(Bag.Trees{t})

  • Ens is a full ensemble returned by fitensemble or a compact ensemble returned by compact.

  • Bag is a full bag of trees returned by TreeBagger or a compact bag of trees returned by compact.

Examples

expand all

View Trained Classification Tree

View textual and graphical displays of a trained classification tree.

Load Fisher's iris data set.

load fisheriris

Train a classification tree using all measurements.

Mdl = fitctree(meas,species);

View textual display of the trained classification tree.

view(Mdl)
Decision tree for classification
1  if x3<2.45 then node 2 elseif x3>=2.45 then node 3 else setosa
2  class = setosa
3  if x4<1.75 then node 4 elseif x4>=1.75 then node 5 else versicolor
4  if x3<4.95 then node 6 elseif x3>=4.95 then node 7 else versicolor
5  class = virginica
6  if x4<1.65 then node 8 elseif x4>=1.65 then node 9 else versicolor
7  class = virginica
8  class = versicolor
9  class = virginica

View graphical display of the trained classification tree.

view(Mdl,'Mode','graph');

View Tree from Bag of Trees

Load Fisher's iris data set.

load fisheriris

Grow a bag of 100 classification trees using all measurements.

rng(1) % For reproducibility
Mdl = TreeBagger(100,meas,species);

Alternatively, you can use fitensemble to grow a bag of classification trees.

Mdl is a TreeBagger model object. Mdl.Trees stores the bag of 100 trained classification trees in a 100-by-1 cell array. That is, each cell in Mdl.Trees contains a CompactClassificationTree model object.

View a graph of the 10th classification tree in the bag.

Tree10 = Mdl.Trees{10};
view(Tree10,'Mode','graph');

By default, the software grows deep trees for bags of trees.

View Tree from Boosted Ensemble

Load Fisher's iris data set.

load fisheriris

Boost an ensemble of 100 classification trees using all measurements.

Mdl = fitensemble(meas,species,'AdaBoostM2',100,'Tree');

Mdl is a ClassificationEnsemble model object. Mdl.Trained stores the ensemble of 100 trained classification trees in a 100-by-1 cell array. That is, each cell in Mdl.Trained contains a CompactClassificationTree model object.

View a graph of the 10th classification tree in the ensemble.

Tree10 = Mdl.Trained{10};
view(Tree10,'Mode','graph');

By default, fitensemble grows shallow trees for boosted ensembles of trees.

Was this topic helpful?