フィルターのクリア

How to save generated tree from classregtree function into array variable

3 ビュー (過去 30 日間)
Tessy
Tessy 2011 年 12 月 29 日
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.

回答 (2 件)

Ilya
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.

Walter Roberson
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

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by