Problem 1: For Homework 8, Problem 1, you re- duced the dimension of a dataset f
ID: 2291487 • Letter: P
Question
Problem 1: For Homework 8, Problem 1, you re- duced the dimension of a dataset from 2 to 1 using linear discriminant analysis. Now you will do the same but with principal component analysis. For the following, show your work and/or screenshots of all calculations, as applicable. (a) Center the dataset from Homework 8, Problem 1 (b) Compute the covariance matrix of the centered (c) Find the two unit eigenvectors of the covariance by subtracting off the mean of each feature. dataset. matrix and their corresponding eigenvalues (d) Transform the normalized 8-by-2 dataset to an other 8-by-2 matrix so each example is its coor- dinates relative to the principal component axes (e) Now reduce the dimension to 1 by giving an 8-by- 1 matrix of each example's first principal compo- nent score. (f) Why are the results from the previous part dif- ferent as compared to Homework 8, Problem 1? Hint: Did you use the vector y from Homework 8 Problem 1? g) How much of the data variance do you retain af- ter reducing the dimension to 1 for this dataset?Explanation / Answer
Matlab Code:
--------------------------------------
clc;clear;
x1 = [4 9 2 6 2 9 3 8 ];
x2 = [1 10 4 8 3 5 5 7];
x1_centred = [x1 - mean(x1)];
x2_centred = [x2 - mean(x2)];
x_centred = [x1_centred x2_centred]';
% To calculate the value of covariance
x_covariance = cov(x1_centred,x2_centred)
% to calculate the eigen value and eigen vector of covariance matrix
[eig_vect, eig_val] = eig(x_covariance)
%transform normalize dataset to priciple componant axes
x_centred_pca = eig_val*[x1_centred;x2_centred]
-----------------------------------------------------
Command Window:
---------------------------------------------------------
x_covariance =
9.1250 5.8393
5.8393 8.2679
eig_vect =
0.6807 -0.7325
-0.7325 -0.6807
eig_val =
2.8414 0
0 14.5514
x_centred_pca =
-3.9070 10.3002 -9.5898 1.7759 -9.5898 10.3002 -6.7484 7.4588
-63.6625 67.3003 -20.0082 38.1975 -34.5596 -5.4568 -5.4568 23.6461
>>