How do I build a tree which has a depth that i want? For example i want to create a decision tree which has a only 3 depth.
load ionosphere
treeModel = fitctree(X,Y)
view(treeModel)
view(treeModel,'mode','graph')
This code create 7 depth tree. I use same data set but i want to create tree which has 3 or 2 depth. How can I do on matlab?
You can control the maximum depth using the MaxDepth
name-value pair argument.
Read the documentation for more details.
treeModel = fitctree(X,Y,'MaxDepth',3);
Try to be as flexible as possible when building up Matlab environments. Also, as per official documentation, note that the MaxDepth
option only applies when using fitctree
on tall arrays.
load ionosphere
treeModel = CreateTreeModel(X,Y,3);
view(treeModel)
view(treeModel,'mode','graph')
function tm = CreateTreeModel(x,y,depth)
if (nargin < 3)
tm = fitctree(x,y);
return;
end
if (depth < 1)
depth = 1;
end
tm = fitctree(x,y,'MaxDepth',depth);
end
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.