How to save generated tree from classregtree function into array variable
1 次查看(过去 30 天)
显示 更早的评论
Hi there,
is there anybody can help me ... I used this code to generate tree from iris dataset, and I want to save generated tree from classregtree function into array variable ? Here is my simple code : =================================
x=load('fisheriris'); t=classregtree(x.meas, x.species)
================================= I got t variable contains :
t =
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
================
My question is : how to save variable t into array variable.
For example : into variable IrisTree,
so I have
IrisTree(1)="1 if x3<2.45 then node 2 elseif x3>=2.45 then node 3 else setosa"
IrisTree(2)="2 class = setosa"
IrisTree(3)="3 if x4<1.75 then node 4 elseif x4>=1.75 then node 5 else versicolor"
........
IrisTree(9)="9 class = virginica"
Many thanks for your help.
Best Regards, tessy.
0 个评论
回答(2 个)
Ilya
2011-12-29
Your t variable contains much more than these 9 lines. It is an object with a whole bunch of methods. The output you see is just a command-window display produced by the DISP method. I suggest that you learn how to extract info about the tree by using its methods. This approach would be more productive than trying to dump the display output into an array.
0 个评论
Walter Roberson
2011-12-29
Untested:
tlines = textscan(evalc('t'), '%s', 'Delimiter', '\n');
or perhaps
tlines = regexp(evalc('t'), '(?m)^.*$', 'match');
That is, evalc(t) would display t and capture the results, but it would be captured using newline characters to separate the lines. The textscan or regexp are there to split on line boundaries in to a cellstr
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!