This commit is contained in:
Michael Zhang 2023-09-21 22:45:23 -05:00
parent 295ebd3ae6
commit 744d84b767
2 changed files with 38 additions and 12 deletions

View file

@ -14,8 +14,8 @@ mnx=-0.1*mxx;%for visualization %mnx = min(X(1,:));
mxy = max(X(2,:)); mxy = max(X(2,:));
mny=-0.1*mxy; % for visualization %mny = min(X(2,:)); mny=-0.1*mxy; % for visualization %mny = min(X(2,:));
figure; %%% figure;
ginput(1); %%% ginput(1);
err = 1; err = 1;
round = 0; round = 0;
while err > 0 while err > 0
@ -24,17 +24,17 @@ while err > 0
w = w + rate*X(:,ii) * Y(ii); %then add (or subtract) this point to w w = w + rate*X(:,ii) * Y(ii); %then add (or subtract) this point to w
x1=mnx:0.01:mxx; x1=mnx:0.01:mxx;
x2=-(w(1)*x1+w(3))/w(2); x2=-(w(1)*x1+w(3))/w(2);
%figure; %%% figure;
clf; %%% clf;
hold on %%% hold on
plot(X(1,pos_idx),X(2,pos_idx),'b*','MarkerSize',10); %%% plot(X(1,pos_idx),X(2,pos_idx),'b*','MarkerSize',10);
plot(X(1,neg_idx),X(2,neg_idx),'r+','MarkerSize',10); %%% plot(X(1,neg_idx),X(2,neg_idx),'r+','MarkerSize',10);
plot(X(1,ii),X(2,ii),'ko','MarkerSize',15); %%% plot(X(1,ii),X(2,ii),'ko','MarkerSize',15);
plot(x1,x2); %%% plot(x1,x2);
xlim([mnx mxx]); %%% xlim([mnx mxx]);
ylim([mny mxy]); %%% ylim([mny mxy]);
%ginput(1); %ginput(1);
pause(0.5); %change the delay % pause(0.5); %change the delay
end end
end end
round = round + 1 round = round + 1

26
zoo/zoo2.m Normal file
View file

@ -0,0 +1,26 @@
% 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