% classify spect data
load spect.mat

Tree  = learnTree(Xtr, Ytr, 7);
Yeval = classTree(Tree, Xtest);
acc   = 100 * sum(Yeval == Ytest)/length(Ytest);

Tree.nodes
Tree.attr
Tree.IG
Tree.class

treeplot(Tree.nodes);
title(['Decision Tree for spect.mat (Accuracy: ' num2str(acc, '%4.2f%%') ')']);

% get the coordinates for the nodes
[xs, ys] = treelayout(Tree.nodes);

for i = 1:length(Tree.nodes);
    % return index of node and parent node
	text(xs(i) + 0.02, ys(i), [num2str(i) ' (' num2str(Tree.nodes(i)) ')']);
    
	if Tree.attr(i) > 0
        % return IG and splitting attribute at the inner nodes
		text(xs(i) + 0.02, ys(i) - 0.03, ['Attr: ' num2str(Tree.attr(i)) ...
		'  IG: ' num2str(Tree.IG(i), '%5.3f')]);
    else
        % return the class at the leafs
		text(xs(i) - 0.02, ys(i) - 0.04, ['Class: ' num2str(Tree.class(i))]);            
	end
end
