[英]Decision Tree in Matlab
我在Matlab中看到了幫助,但是他們提供了一個示例,但沒有解釋如何使用'classregtree'函數中的參數。 任何幫助解釋'classregtree'與其參數的使用將不勝感激。
函數classregtree的文檔頁面是不言自明的......
讓我們回顧一下分類樹模型的一些最常見的參數:
一個完整的例子來說明這個過程:
%# 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'
上面的classregtree
類已經過時,並且被R2011a中的ClassificationTree
和RegressionTree
類所取代(參見fitctree
和fitrtree
函數,R2014a中的新函數)。
這是更新的示例,使用新的函數/類:
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.