% % Examples 9.7 % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clear all; close all; clc; addpath('../../Code/CSTool'); load iris % This loads up three matrices: setosa, versicolor and virginica. % % We will use the classes SETOSA AND VIRGINICA. % % Note that the priors are equal, so the decision is % based only on the class-conditional probabilities. ncc = 0; setosa(:,3:4)=[]; virginica(:,3:4)=[]; [nset,d]=size(setosa); [nvir,d]=size(virginica); n = nvir + nset; % Loop first through all of the patterns corresponding % to setosa. Here correct classification % is obtained if pxgver > pxgvir; muvir = mean(virginica); covvir = cov(virginica); % These will be the same for this part. for i = 1:nset % Get the test point and the training set settrain = setosa; % This is the testing point. x = settrain(i,:); % Delete from training set. % The result is the training set. settrain(i,:)=[]; muset = mean(settrain); covset = cov(settrain); pxgset=csevalnorm(x,muset,covset); pxgvir=csevalnorm(x,muvir,covvir); if pxgset > pxgvir % then we correctly classified it ncc = ncc+1; end end % Loop through all of the patterns of virginica notes. % Here correct classification is obtained when % pxgvir > pxxgver muset = mean(setosa); covset = cov(setosa); % These remain the same for the following. for i = 1:nvir % Get the test point and training set virtrain = virginica; x = virtrain(i,:); virtrain(i,:)=[]; muvir = mean(virtrain); covvir = cov(virtrain); pxgset = csevalnorm(x,muset,covset); pxgvir = csevalnorm(x,muvir,covvir); if pxgvir > pxgset % then we correctly classified it ncc = ncc+1; end end pcc = ncc/n; fprintf('pcc = %10.6f\n',pcc);