Accelerating the pace of engineering and science

# risk

Class: classregtree

Node risks

## Syntax

r = risk(t)
r = risk(t,nodes)

## Description

r = risk(t) returns an n-element vector r of the risk of the nodes in the tree t, where n is the number of nodes. The risk r(i) for node i is the node error e(i) (computed by nodeerr) weighted by the node probability p(i) (computed by nodeprob).

r = risk(t,nodes) takes a vector nodes of node numbers and returns the risk values for the specified nodes.

## Examples

Create a classification tree for Fisher's iris data:

```load fisheriris;

t = classregtree(meas,species,...
'names',{'SL' 'SW' 'PL' 'PW'})
t =
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  class = virginica
8  class = versicolor
9  class = virginica

view(t)```

```e = nodeerr(t);
p = nodeprob(t);
r = risk(t);

r
r =
0.6667
0
0.3333
0.0333
0.0067
0.0067
0.0133
0
0

e.*p
ans =
0.6667
0
0.3333
0.0333
0.0067
0.0067
0.0133
0
0```

## References

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