[英]Decision Tree in Matlab
I saw the help in Matlab, but they have provided an example without explaining how to use the parameters in the 'classregtree' function. 我在Matlab中看到了帮助,但是他们提供了一个示例,但没有解释如何使用'classregtree'函数中的参数。 Any help to explain the use of 'classregtree' with its parameters will be appreciated.
任何帮助解释'classregtree'与其参数的使用将不胜感激。
The documentation page of the function classregtree is self-explanatory... 函数classregtree的文档页面是不言自明的......
Lets go over some of the most common parameters of the classification tree model: 让我们回顾一下分类树模型的一些最常见的参数:
A complete example to illustrate the process: 一个完整的例子来说明这个过程:
%# load data
load carsmall
%# construct predicting attributes and target class
vars = {'MPG' 'Cylinders' 'Horsepower' 'Model_Year'};
x = [MPG Cylinders Horsepower Model_Year]; %# mixed continous/discrete data
y = cellstr(Origin); %# class labels
%# train classification decision tree
t = classregtree(x, y, 'method','classification', 'names',vars, ...
'categorical',[2 4], 'prune','off');
view(t)
%# test
yPredicted = eval(t, x);
cm = confusionmat(y,yPredicted); %# confusion matrix
N = sum(cm(:));
err = ( N-sum(diag(cm)) ) / N; %# testing error
%# prune tree to avoid overfitting
tt = prune(t, 'level',3);
view(tt)
%# predict a new unseen instance
inst = [33 4 78 NaN];
prediction = eval(tt, inst) %# pred = 'Japan'
The above classregtree
class was made obsolete, and is superseded by ClassificationTree
and RegressionTree
classes in R2011a (see the fitctree
and fitrtree
functions, new in R2014a). 上面的
classregtree
类已经过时,并且被R2011a中的ClassificationTree
和RegressionTree
类所取代(参见fitctree
和fitrtree
函数,R2014a中的新函数)。
Here is the updated example, using the new functions/classes: 这是更新的示例,使用新的函数/类:
t = fitctree(x, y, 'PredictorNames',vars, ...
'CategoricalPredictors',{'Cylinders', 'Model_Year'}, 'Prune','off');
view(t, 'mode','graph')
y_hat = predict(t, x);
cm = confusionmat(y,y_hat);
tt = prune(t, 'Level',3);
view(tt)
predict(tt, [33 4 78 NaN])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.