MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab中的决策树 (https://www.labfans.com/bbs/showthread.php?t=23013)

poster 2019-12-10 16:49

Matlab中的决策树
 
我在Matlab中看到了帮助,但是他们提供了一个示例,但没有说明如何使用'classregtree'函数中的参数。任何帮助解释“ classregtree”及其参数使用的帮助将不胜感激。


回答:
函数[URL="http://www.mathworks.com/help/stats/classregtree.html"]classregtree[/URL]的文档页面不言自明...

让我们回顾一下分类树模型的一些最常见的参数:
[LIST][*] [B]x[/B] :数据矩阵,行是实例,cols是预测属性[*] [B]y[/B] :列向量,每个实例的类标签[*] [B]categorical[/B] :指定哪些属性是离散类型(而不是连续的)[*] [B]方法[/B] :产生分类树还是回归树(取决于类类型)[*] [B]名称[/B] :为属性指定名称[*] [B]prune[/B] :启用/禁用减少错误的修剪[*] [B]minparent / minleaf[/B] :如果要进一步拆分,则允许指定节点中的最小实例数[*] [B]nvartosample[/B] :用于随机树(考虑每个节点的K个随机选择的属性)[*] [B]权重[/B] :指定加权实例[*] [B]成本[/B] :指定成本矩阵(各种错误的惩罚)[*] [B]splitcriterion[/B] :用于在每次拆分时选择最佳属性的标准。我只熟悉基尼系数,它是信息增益标准的一种变体。[*] [B]priorityprob[/B] :明确指定先验课程的概率,而不是从训练数据中计算[/LIST]一个完整的示例来说明该过程:

%# 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' [IMG]https://i.stack.imgur.com/JvaG1.png[/IMG]

[B]更新: [/B]

上面的[URL="http://www.mathworks.com/help/stats/classregtree.html"]classregtree[/URL]类已作废,并[URL="http://www.mathworks.com/help/stats/classregtree.html"]classregtree[/URL]的[URL="http://www.mathworks.com/help/stats/classificationtree-class.html"]ClassificationTree[/URL]和[URL="http://www.mathworks.com/help/stats/regressiontree-class.html"]RegressionTree[/URL]类取代(请参阅[URL="http://www.mathworks.com/help/stats/fitctree.html"]fitctree[/URL]和[URL="http://www.mathworks.com/help/stats/fitrtree.html"]fitrtree[/URL]函数)。

这是使用新功能/类的更新示例:

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])

[url=https://stackoverflow.com/questions/1960430]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:03

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.