您的位置:首页 > 其它

CART算法实现之可视化

2013-12-24 11:59 369 查看


function filename = viz_tree( tree )
%UNTITLED Summary of this function goes here
% Visualiz the tree using graphviz
global index;
index  = 0;
fid = fopen('Visualization.dot','w+');
fprintf(fid, 'digraph G {\n');
fprintf(fid, 'fontname = "Bitstream Vera Sans"\n');
fprintf(fid, 'fontsize = 8\n');
fprintf(fid, 'node[fontname = "Bitstream Vera Sans"\n');
fprintf(fid, '    fontsize = 8\n');
fprintf(fid, '    shape = "record"]\n');
fprintf(fid, 'edge [fontname = "Bitstream Vera Sans"\n');
fprintf(fid, '      fontsize = 8]\n');
visual( tree ,fid);
fprintf(fid,'}');
fclose(fid);
filename = 'Visualization.dot';

function nodename = visual( tree ,fid)
global index;
index = index + 1;
nodename = ['node' num2str(index)];
if isnumeric(tree.Raction)
%Reached an end node
fprintf(fid, '%s[label ="{class = %d|+Error Rate : %5f}"]\n',nodename, tree.Raction(1),tree.Resub);
else
fprintf(fid, '%s[label ="{Left : %s|+Right : %s|+Alpha : %6f}"]\n',nodename, tree.Laction, tree.Raction, tree.Alpha);
nl = visual(tree.left, fid);
nr = visual(tree.right, fid);
fprintf(fid, '%s -> %s\n',nodename, nl);
fprintf(fid, '%s -> %s\n',nodename, nr);
%fprintf(fid, 'nodename[label =%s|+Leafcnt : %d|+Alpha : %6f]\n', tree.Raction, tree.Leafcnt, tree.Alpha);
%Rl = visual(tree.left, fid);
%RR = visual(tree.right, fid);
end








内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: