📄 detreeexp45.m
字号:
global data textdata
global grpnum node grpname tree
global cost secost ntermnodes bestlevel
% 计算分类代价
resubcost = treetest(tree,'resub');
[cost,secost,ntermnodes,bestlevel] = treetest(tree,'cross',data(:,1:2), textdata(:,1));
plot(ntermnodes,cost,'b-', ntermnodes,resubcost,'r--')
figure(gcf);
xlabel('叶结点数量');
ylabel('代价 (错误分类误差)');
legend('交叉确认法','回代法');
%% Which tree should we choose? A simple rule would be to choose the tree with the smallest cross-validation error.
% While this may be satisfactory, we might prefer to use a simpler tree if it is roughly as good as a more complex tree.
% The rule we will use is to take the simplest tree that is within one standard error of the minimum.
% That's the default rule used by the TREETEST function.
[mincost,minloc] = min(cost);
cutoff = mincost + secost(minloc);
hold on
plot([0 20], [cutoff cutoff], 'k:')
plot(ntermnodes(bestlevel+1), cost(bestlevel+1), 'mo')
legend('交叉确认法','回代法','最小代价+一个标准误差.','最佳选择')
hold off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -