csci5521/zoo/zoo2.m
2023-09-21 22:45:23 -05:00

26 lines
No EOL
825 B
Matlab

% Change K here to any integer < 96
K = 60;
load zoo; %load matlab data
sample_idxs = randperm(96, K)
sample_data = trn_data(sample_idxs, : )
sample_lab = trn_lab(sample_idxs, : )
t = fitctree(sample_data,sample_lab,'PredictorNames', fields); %train a decision tree for classification
view(t,'Mode','graph'); %visualize the tree t
% %for visualization
% allHandles=findall(groot,'Type','text')
% set(allHandles,'FontSize',24)
% pause;
% h = findall(groot,'Type','figure');
% close(h);
% for i=1:6
% clf(gcf);
% imshow(strcat(tst_names{i},'.png'));
% set(gcf,'Position',[0 0 700 700]+300);
% title(tst_names{i},'FontSize',40);
% pause;
% y=predict(t,tst_data(i,:)); %classify a test sample by tree t
% title(sprintf('%s is %s',tst_names{i},y{1}),'FontSize',40,'color', 'r');
% pause;
% end