Docsity

Principal Component Analysis (PCA) - Prof. Nguyen Thanh, Lecture notes of Machine Learning

Toggle sidebar
bg1
Machine Learning 2
1
Machine Learning 2
1. PCA
Steps to PCA:
1. Standardize the data: If the features in the dataset have different scales,
it is important to standardize them (subtract the mean and divide by the
standard deviation) to ensure that each feature contributes equally to the
analysis.
2. Compute the covariance matrix: The covariance matrix measures the
relationships between the different features in the dataset. It provides
information about how the features vary together.
3. Calculate the eigenvectors and eigenvalues: The eigenvectors and
eigenvalues of the covariance matrix represent the principal components.
The eigenvectors are the directions
of maximum variance, while the corresponding eigenvalues indicate the
amount of variance explained by each principal component.
4. Select the principal components: To reduce the dimensionality, you
can select a subset of the principal components based on their
corresponding eigenvalues. Typically, you would choose the top-k
components that explain a significant portion of the variance (e.g.,90% or
more).
pf3
pf4
pf5

Partial preview of the text

Download Principal Component Analysis (PCA) - Prof. Nguyen Thanh and more Lecture notes Machine Learning in PDF only on Docsity!

Machine Learning 2

1. PCA

Steps to PCA:

  1. Standardize the data: If the features in the dataset have different scales,

it is important to standardize them (subtract the mean and divide by the

standard deviation) to ensure that each feature contributes equally to the

analysis.

  1. Compute the covariance matrix : The covariance matrix measures the

relationships between the different features in the dataset. It provides

information about how the features vary together.

  1. Calculate the eigenvectors and eigenvalues: The eigenvectors and

eigenvalues of the covariance matrix represent the principal components.

The eigenvectors are the directions

of maximum variance, while the corresponding eigenvalues indicate the

amount of variance explained by each principal component.

  1. Select the principal components: To reduce the dimensionality, you

can select a subset of the principal components based on their

corresponding eigenvalues. Typically, you would choose the top-k

components that explain a significant portion of the variance (e.g.,90% or

more).

  1. Transform the data: Multiply the standardized data by the selected

principal components to obtain the transformed dataset with reduced

dimensionality. Each data point is projected onto the new principal

component axes.

Set up bài toán PCA:

Given dataset withe mean = 0.

PCA is the method in which we will find a new basis, a.k.a a projection matrix,

where the original dataset can be projected onto it to reduce the data dimension

but important information still retained.

We assume there exist a low-dimension compressed representation of a data

point given by:

where we compressed of D dimensions to to M dimensions (M < D), and

the projection matrix is:

Note that also has zero mean:

We need to find a matrix that retains as much information as possible when

compressing data by projecting it onto the subspace spanned by the columns

of. Retaining most information after data compression is

equivalent to capturing the largest amount of variance in the low-dimensional

code.

We maximize the variance of the low-dimensional code using a sequential

approach. First, we consider the case when X is projected onto a single vector

(basically, this is when the projection matrix is just a vector and we

X = {x 1 , x 2 , ..., x (^) n} μ

x = ∗ x − μx

xn

z (^) n =B x

T n

xn zn

B = [b 1 , b 2 , .., b (^) M ] ∈R

D×M

z E (^) z [z] =E (^) x[ B x] =

T B E [x] =

T x 0

B

b 1 , b 2 , .., bM B

b ∈ R D B

The variance of the data projected onto a one-dimensional subspace equals

the eigenvalue that is associated with the basis vector b that spans this

subspace.

Therefore, to maximize the variance of the low-dimensional code, we choose

the basis vector associated with the largest eigenvalue principal

component of the data covariance matrix. This eigenvector is called the first

principal component.

The finding of vector b above can be viewed as the finding of a direction or an

axis that data varies the most. Suppose we want to find another direction besides

the one we have found, we can construct the similar vector projection problem to

find the largest variance possible, or actually the largest eigenvalue possible.

Now what we derive will be the second largest eigenvalue.

Therefore, if we want to find axes to project data, we can choose

eigenvectors of the data variance matrix that associates with

largest eigenvalues, each eigenvector corresponding to a new axis of projection.

The projection

matrix

is formed by those eigenvectors, i.e:.

Finally, the projection of dataset onto given by

will result, in new representation of data, i. e (M features

and N samples).

Note: In case me in the future forget how this algorithm works,

remember features of are not derived by removing some less

important features of X (and keeping the remaining) but by synthesizing

information from the whole dataset X and compressing them into M

new features.

Summary :

V = b Sb =

T b λb =

T λ

M M

b 1 , b 2 , ..., bM M

B B = [b 1 , b 2 , ..., bM ]

X ∈ R

D×N B ∈ R

D×M X =

∼

B X

T X ∈

∼ R

M ×N

X

∼