I am trying to make a decision tree but the outcome is strange and I can't figure out where is wrong. There are seven variables, each of which I use 1 or 2 to represent their meaning, for example, for variable 1 the number 1 is warm and 2 is cold, for variable 2 the number 1 is yes and 2 is no.
vars = {'TEMP' 'SKIN' 'BIRTH' 'AQUATIC' 'AERIAL' 'LEGS' 'HIBER'};
x = [1 1 1 2 2 1 2
2 2 2 2 2 2 1
2 2 2 1 2 2 2
1 1 1 1 2 2 2
2 1 2 1 2 1 1
2 2 2 2 2 1 2
1 1 1 2 1 1 1
1 1 2 2 1 1 2
1 1 1 2 2 1 2
2 2 1 1 2 2 2
2 2 2 1 2 1 2
1 1 2 1 2 1 2
1 1 1 2 2 1 1
2 2 2 1 2 2 2
2 1 2 1 2 1 1];
s = {'M';'R';'F';'M';'A';'R';'M';'B';'M';'F';'R';'B';'M';'F';'A'};
y = cellstr(s);
t = classregtree(x, y, 'method','classification', 'names',vars,...
'categorical',[1 7], 'prune','off');
view(t)
The outcome is only one step tree without other information. What is wrong with this?
I'm not an expert of decision trees, anyway, playing a little bit with the parameters of classregtree
( minparent
, to be exact):
vars = {'TEMP' 'SKIN' 'BIRTH' 'AQUATIC' 'AERIAL' 'LEGS' 'HIBER'};
x = [1 1 1 2 2 1 2
2 2 2 2 2 2 1
2 2 2 1 2 2 2
1 1 1 1 2 2 2
2 1 2 1 2 1 1
2 2 2 2 2 1 2
1 1 1 2 1 1 1
1 1 2 2 1 1 2
1 1 1 2 2 1 2
2 2 1 1 2 2 2
2 2 2 1 2 1 2
1 1 2 1 2 1 2
1 1 1 2 2 1 1
2 2 2 1 2 2 2
2 1 2 1 2 1 1];
y = {'M';'R';'F';'M';'A';'R';'M';'B';'M';'F';'R';'B';'M';'F';'A'};
t = classregtree(x,y,'method','classification','Names',vars, ...
'categorical',[1 7],'prune','off','minparent',1);
view(t);
I've been able to reproduce something that looks fine. Anyway, since Matlab release 2011A, classregtree
has become obsolete and has been superseded by fitrtree
(RegressionTree) and fitctree
(ClassificationTree) functions ( classregtree
is being kept for retrocompatibility reasons only). I recommend you to update your code and use those functions instead:
t = fitctree(x,y,'PredictorNames',vars, ...
'CategoricalPredictors',{'TEMP' 'HIBER'},'Prune','off','MinParentSize',1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.