Professional Documents
Culture Documents
Pattern Recognition Home Assignment 2
Pattern Recognition Home Assignment 2
AIM:
To classify the Fisher Iris Standard Data Set into three classes namely “setosa”,
“versicolor” and “virginica” using decision boundaries.
The parameters: Petal Length and Petal Width is used to classify the data set.
MATLAB CODE:
clc;
clear all;
close all;
setosa_indices = strcmp('setosa',species);
setosa = meas(setosa_indices,:);
versicolor_indices = strcmp('versicolor',species);
versicolor = meas(versicolor_indices,:);
virginica_indices = strcmp('virginica',species);
virginica = meas(virginica_indices,:);
setosaOBS = setosa(:,3:4);
versicolorOBS = versicolor(:,3:4);
virginicaOBS = virginica(:,3:4);
r_setosa = corrcoef(setosaOBS);
r_versicolor = corrcoef(versicolorOBS);
r_virginica = corrcoef(virginicaOBS);
gridres = 100;
x_min = 0;
x_max = 7;
y_min = 0;
y_max = 3;
xspace = linspace(x_min, x_max, gridres);
yspace = linspace(y_min, y_max, gridres);
[X Y] = meshgrid(xspace, yspace);
gridpoints = [X(:) Y(:)];
npoints = size(gridpoints, 1);
for i = 1:3
dist = gridpoints - (ones(npoints,1)*centres(i,:));
Q = chol(cov(:,:,i));
term = dist*inv(Q);
px_C(:,i) = exp(-0.5*sum(term .* term, 2))./(normalfact*prod(diag(Q)));
end
hold on;
annotation('textbox',...
[0.167071428571429 0.20952380952381 0.133928571428571
0.0642857142857143],...
'String',{'SETOSA'},...
'FontWeight','bold',...
'FontSize',9,...
'FontName','Arial',...
'FontAngle','italic',...
'LineStyle','none');
annotation('textbox',...
[0.4135 0.266666666666668 0.189285714285714 0.0642857142857143],...
'String',{'VERSICOLOR'},...
'FontWeight','bold',...
'FontSize',9,...
'FontName','Arial',...
'FontAngle','italic',...
'LineStyle','none');
annotation('textbox',...
[0.595642857142856 0.785714285714289 0.158928571428571
0.0642857142857143],...
'String',{'VIRGINICA'},...
'FontWeight','bold',...
'FontSize',9,...
'FontName','Arial',...
'FontAngle','italic',...
'LineStyle','none');
RESULT:
VIRGINICA
2.5
2
PETAL WIDTH -->
1.5
VERSICOLOR
0.5 SETOSA
0
0 1 2 3 4 5 6 7
PETAL LENGTH -->