1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| clear
load fisheriris x=meas(:,1:2); y=categorical(species); labels = categories(y); figure(1) gscatter(x(:,1),x(:,2),species,'rgb','osd'); xlabel('Sepal length'); ylabel('Sepal width');
classifier{1}=ClassificationDiscriminant.fit(x,y); classifier{2}=ClassificationTree.fit(x,y); classifier{3}=ClassificationKNN.fit(x,y);
classifier_name={'Discriminant Analysis','Classification Tree','Nearest Neighbor'};
[xx1,xx2]=meshgrid(4:.01:8,2:.01:4.5); figure(2) for ii=1:numel(classifier) ypred=predict(classifier{ii},[xx1(:) xx2(:)]); h(ii)=subplot(2,2,ii); gscatter(xx1(:),xx2(:),ypred,'rgb'); title(classifier_name{ii},'FontSize',15) legend off axis tight end
figure(3) predictResult=predict(classifier{2},x); y=categorical(y); predictResult=categorical(predictResult); plotconfusion(y,predictResult);
|