[英]Matlab decision tree
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.
有七个变量,我分别使用1或2来表示它们的含义,例如,对于变量1,数字1是温暖的,而2是寒冷,对于变量2,数字1是是的,而2是否。
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): 无论如何,我不是决策树方面的专家,只是在使用
classregtree
的参数( minparent
,是minparent
):
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). 无论如何,因为Matlab的发布2011A,
classregtree
已经过时并已被取代fitrtree
(RegressionTree)和fitctree
(ClassificationTree)功能( classregtree
正在只能保持retrocompatibility原因)。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.