Uploaded by Upendra Malawaraarachchi

FDA IRIS

advertisement
FDA to IRIS Data set
x = iris_dataset;
figure(1)
plot(x')
xlabel('index');
ylabel('data');
title('Iris data')
hold off
Iris: Two Class
let's consider the data set in to 2 catagories.
ix0 = 1:50;
ix1 = 51:150;
figure(2)
histogram(x(1,1:50))
hold on
histogram(x(1,51:150))
grid on
title('Histogram before applying FDA - Iris: Two Class')
hold off
figure(3)
plot(x(1,ix0),x(2,ix0),'ro', 'LineWidth' , 2);hold on;
plot(x(1,ix1),x(2,ix1),'bo', 'LineWidth' , 2);
title('Original IRIS Two-Class')
legend('ix0 - 50','ix1 - 100')
grid on;
axis equal;
To project the data to a smaller dimension and to avoid class overlapping, FLD maintains 2 properties.
• A large variance among the dataset classes.
• A small variance within each of the dataset classes.
Mean
m0 = mean(x(:,ix0)')'; %mean of omega_0
m1 = mean(x(:,ix1)')'; %mean of not_omega_0
% 4 x 1
% 4 x 1
Between class variance (Sb) And Within class variance (Sw)
%Sb = (m1-m0)*(m1-m0)'; % 4 x 4
Sb = (m1-m0)'*(m1-m0);
S0 = 50*cov(x(:,ix0)');
S1 = 100*cov(x(:,ix1)');
Sw = S0 + S1;
To find the projection with the following properties, FLD learns a weight vector V with the following
criterion.
%[V,D] = eigs((Sw)\Sb);
[V,D] = eigs(inv(Sw)*Sb);
%[V,D] = inv(Sw)*(m1-m0);
Y = V'*x;
% 4 x 150
figure(4)
plot(Y(1,ix0),Y(2,ix0),'ro', 'LineWidth' , 2);hold on;
plot(Y(1,ix1),Y(2,ix1),'bo', 'LineWidth' , 2);
title('FDA: IRIS Two-Class')
legend('ix0 - 50','ix1 - 100')
grid on;
axis equal;
figure(5)
histogram(Y(1,1:50))
hold on
histogram(Y(1,51:150))
grid on
title('Histogram after applying FDA - Iris: Two Class')
hold off
figure(6)
plot3(Y(1,ix0),Y(2,ix0),Y(3,ix0),'ro', 'LineWidth' , 2);hold on;
plot3(Y(1,ix1),Y(2,ix1),Y(3,ix1),'bo', 'LineWidth' , 2);
title('FDA: IRIS Two-Class')
legend('ix0 - 50','ix1 - 100')
grid on;
axis equal;
Iris: Multi-Class
x =
ix1
ix2
ix3
iris_dataset;
= 1:50;
= 51:100;
= 101:150;
let's consider the data set in to 2 catagories.
figure(7)
histogram(x(1,1:50))
hold on
histogram(x(1,51:100))
hold on
histogram(x(1,101:150))
grid on
title('Histogram before applying FDA - Iris: Multi-Class')
hold off
figure(8)
plot(x(1,ix1),x(2,ix1),'ro', 'LineWidth' , 2);hold on;
plot(x(1,ix2),x(2,ix2),'bo', 'LineWidth' , 2);
plot(x(1,ix3),x(2,ix3),'ko', 'LineWidth' , 2);
title('Original IRIS Multi-Class')
legend('ix1 - 50','ix2 - 50','ix3 - 50')
grid on;
axis equal;
Mean
m = mean(x')';
m1 = mean(x(:,ix1)')';
m2 = mean(x(:,ix2)')';
m3 = mean(x(:,ix3)')';
Between class variance (Sb) And Within class variance (Sw)
%Sb = (m1-m)*(m1-m)' + (m2-m)*(m2-m)' + (m3-m)*(m3-m)';
Sb = 50*(m1-m)'*(m1-m) + 50*(m2-m)'*(m2-m) + 50*(m3-m)'*(m3-m);
S1 = 50*cov(x(:,ix1)');
S2 = 50*cov(x(:,ix2)');
S3 = 50*cov(x(:,ix3)');
Sw = S1 + S2 + S3;
[V,D] = eigs(inv(Sw)*Sb);
Y = V'*x;
figure(9)
plot(Y(1,ix1),Y(2,ix1),'ro', 'LineWidth' , 2);hold on;
plot(Y(1,ix2),Y(2,ix2),'bo', 'LineWidth' , 2);hold on;
plot(Y(1,ix3),Y(2,ix3),'ko', 'LineWidth' , 2);hold on;
title('FDA: IRIS Multi-Class')
legend('ix1 - 50','ix2 - 50','ix3 - 50')
grid on;
axis equal;
figure(10)
histogram(Y(1,1:50))
hold on
histogram(Y(1,51:100))
grid on
histogram(Y(1,101:150))
grid on
title('Histogram after applying FDA - Iris: Multi-Class')
hold off
figure(11)
plot3(Y(1,ix1),Y(2,ix1),Y(3,ix1),'ro', 'LineWidth' , 2);hold on;
plot3(Y(1,ix2),Y(2,ix2),Y(3,ix2),'bo', 'LineWidth' , 2);hold on;
plot3(Y(1,ix3),Y(2,ix3),Y(3,ix3),'ko', 'LineWidth' , 2);hold on;
title('FDA: IRIS Multi-Class')
legend('ix1 - 50','ix2 - 50','ix3 - 50')
grid on;
Download