cutvar

Class: classregtree

Cut variable names

Syntax

v = cutvar(t)
v = cutvar(t,nodes)
[v,num] = cutvar(...)

Description

v = cutvar(t) returns an n-element cell array v of the names of the variables used for branching in each node of the tree t, where n is the number of nodes. These variables are sometimes known as cut variables. For leaf nodes, v contains an empty string.

v = cutvar(t,nodes) takes a vector nodes of node numbers and returns the cut variables for the specified nodes.

[v,num] = cutvar(...) also returns a vector num containing the number of each variable.

Examples

Create a classification tree for car data:

load carsmall

t = classregtree([MPG Cylinders],Origin,...
                 'names',{'MPG' 'Cyl'},'cat',2)
t = 
Decision tree for classification
 1  if Cyl=4 then node 2 elseif Cyl in {6 8} then node 3 else USA
 2  if MPG<31.5 then node 4 elseif MPG>=31.5 then node 5 else USA
 3  if Cyl=6 then node 6 elseif Cyl=8 then node 7 else USA
 4  if MPG<21.5 then node 8 elseif MPG>=21.5 then node 9 else USA
 5  if MPG<41 then node 10 elseif MPG>=41 then node 11 else Japan
 6  if MPG<17 then node 12 elseif MPG>=17 then node 13 else USA
 7  class = USA
 8  class = France
 9  class = USA
10  class = Japan
11  class = Germany
12  class = Germany
13  class = USA

view(t)

[v,num] = cutvar(t)
v = 
    'Cyl'
    'MPG'
    'Cyl'
    'MPG'
    'MPG'
    'MPG'
    ''
    ''
    ''
    ''
    ''
    ''
    ''
num =
     2
     1
     2
     1
     1
     1
     0
     0
     0
     0
     0
     0
     0

References

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

Was this topic helpful?