What predictor variables are used for a given pruning level in a classregtree?

I'm working with classification and regression trees - I can define them, prune them, and even view the pruned tree with the predictor variable names displayed using the view() function. However, for an optimally pruned tree, I want to know which of the 6 predictor variables are actually being used. I can see this in the view(Tree) display, but I need some sort of index to be returned in my code, so I don't have to manually open a tree, assess the variables, and store which ones ended up being significant every time. Is there a way to do this?
To reiterate - for a classregtree and a given pruning level, how can I extract the predictor variables (either a name or index) that are being used? My optimally pruned trees tend to disregard at least one of my 6 predictor variables, and I want to know which are actually used without manually viewing the tree.
I'm using Matlab 7.12.0.635 win64 Thank you very much!

 採用された回答

Ilya
Ilya 2013 年 10 月 28 日
Prune the tree to the desired level using the prune method. Then use the cutvar method to see what variables are used for splits in each node. For example:
load ionosphere
t = classregtree(X,Y);
t = prune(t,'level',3);
varsUsedInTree = ismember(names(t),cutvar(t)')
Typing methods(t) or looking at the classregtree doc would give you a full list of methods.

3 件のコメント

Rebecca
Rebecca 2013 年 10 月 29 日
Thank you for your help! I did not notice the cutvar method before. We ended up using:
t = classregtree(X, Y,'names',cellArray);
[~,~,~,bestLevel] = test(t, 'crossvalidate', X, Y);
t = prune(t, 'level', bestLevel);
varsUsedInTree = t.names(ismember(t.names,cutvar(Tree2)));
cev
cev 2013 年 11 月 12 日
when I run your code I get this message in Matlab 7.10.0(R2010a)
??? Undefined function or method 'names' for input arguments of type 'classregtree'.
Error in ==> Untitled2 at 4 varsUsedInTree = ismember(names(t),cutvar(t)')
Ilya
Ilya 2013 年 11 月 12 日
Replace
ismember(names(t),cutvar(t)')
with
ismember(t.names,cutvar(t))

サインインしてコメントする。

その他の回答 (0 件)

製品

質問済み:

2013 年 10 月 25 日

コメント済み:

2013 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by