09 Pca
09 Pca
COMPONENT
ANALYSIS(PCA)
ENGR. SAJID SALEEM
CSAL4243
PRINCIPAL COMPONENT ANALYSIS
• Principal component analysis (PCA) is a statistical procedure that uses an orthogonal
transformation to convert a set of observations of possibly correlated variables into a set of
values of linearly uncorrelated variables called principal components.
OR
• PCA also called Principal component analysis is used for reducing the dimension of the dataset
to a lower dimension
• where it can be analyzed more easily
• and also keep all the relevant information of the dataset without any loss.
• In order to multiply a matrix by a vector, the matrix must have as many columns as the vector
has rows
• We might also find ourselves multiplying matrices by vectors when solving linear equations.
• Multiplying a vector by a matrix is much simpler than multiplying two different matrices.
• When we multiply a vectors by matrix, the vector might rotate, stretch, shrink or change
direction.
• Example: x = =
PRINCIPAL COMPONENT ANALYSIS
• Quick review (Eigenvector and Eigenvalue)
• An eigenvector is a non-zero vector that doesn't change direction when a linear transformation
is applied to it ( when you multiply it by a matrix)
• Eigenvectors are those vectors that are only stretched, with neither rotation nor trim, and keep
pointing in the same direction.
• The corresponding eigenvalue is the factor by which an eigenvector is stretched or
compressed.
• If the eigenvalue is negative, the eigenvector's direction is reversed.
• A covariance matrix (also known as auto-covariance matrix, dispersion matrix, variance matrix,
or variance–covariance matrix)
• is a square matrix giving the covariance between each pair of elements of a given random
vector.
PRINCIPAL COMPONENT ANALYSIS
• Let us understand PCA by an example for conversion of date from 2D to 1D
• Reduce the 2D data given below to 1D data:
Feature Example 1 Example 2 Example 3 Example 4
X1 4 8 13 7
X2 11 4 5 14
• = =8
• = = 8.5
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Step 2: Calculate Covariance Matrix Feature
1 2 3 4
• S= X1 4 8 13 7 = 8
X2 11 4 5 14 = 8.5
• = =
= 14
• =
=
= -11
• = = -11
• =
= So, Covariance Matrix:
= 23
S=
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Step 3: Eigenvalues of Covariance Matrix Feature
1 2 3 4
X1 4 8 13 7 = 8
X2 11 4 5 14 = 8.5
• The characteristic equation of the covariance matrix is,
• 0 = det(S- λI) S=
• = I=
• = 2 - 37 + 201
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Step 3: Eigenvalues of Covariance Matrix Feature
1 2 3 4
X1 4 8 13 7 = 8
X2 11 4 5 14 = 8.5
• = 2 - 37 + 201
• Finding the roots of the quadratic equation:
• = = =
• 1 = = 30.39
• 2 = = 6.61
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Step 4: Computation of Eigenvectors Feature
1 2 3 4
X1 4 8 13 7 = 8
X2 11 4 5 14 = 8.5
• Eigenvector => =
• = (S- λI) => =>
• Now:
• =0 -①
• =0 -②
• So
• = 11t
• = (14- )t Taking t=1, we get eigenvector corresponding to Covariance Matrix as:
=
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Next we calculate PCA, for that we consider Feature 1 2 3 4
the largest Eigenvalue X1 4 8 13 7 = 8
• = 30.39 X2 11 4 5 14 = 8.5
1
• 2 = 6.61
• Next, to find a unit eigenvector, we compute the length of X1 which is given by:
• = => =>
• = 19.7348
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Finally, a unit eigenvector corresponding Feature
1 2 3 4
to λ1 is : X1 4 8 13 7 = 8
X2 11 4 5 14 = 8.5
• e1 = =>
1 = 30.39
= 19.7348
• e1 =
2 = 6.61
• e2 =
= ??
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• Step 5: Compute first principal components Feature
1 2 3 4
X1 4 8 13 7 = 8
• Let X2 11 4 5 14 = 8.5
• e1T =>
• = (0.5574) () + (-0.8303) ()
PRINCIPAL COMPONENT ANALYSIS
Example Example Example Example
• First Principal Component for Example1: Feature
1 2 3 4
X1 4 8 13 7 = 8
• X2 11 4 5 14 = 8.5
• =
• Next, we drop perpendiculars from the given data points to the e1-axis