0% found this document useful (0 votes)
2 views2 pages

Simple Dataset

Uploaded by

Millata Hanifya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Simple Dataset

Uploaded by

Millata Hanifya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PCA:

Simple Dataset

We'll use this 2D dataset with 3 data points:

X = [[2.5, 2.4],
[0.5, 0.7],
[2.2, 2.9]]
Each row is a data point, and each column is a feature.
Step-by-step PCA

Step 1: Mean-center the data

Compute the mean of each column:

mean = [ (2.5+0.5+2.2)/3 , (2.4+0.7+2.9)/3 ] = [1.73, 2.0]


Subtract the mean from each data point:

X_centered = [[2.5-1.73, 2.4-2.0], => [0.77, 0.4]


[0.5-1.73, 0.7-2.0], => [-1.23, -1.3]
[2.2-1.73, 2.9-2.0]] => [0.47, 0.9]
Step 2: Covariance Matrix

Cov = (1/(n-1)) * X_centered.T * X_centered


Compute it manually:

Cov = [[(0.77² + (-1.23)² + 0.47²)/2, (0.77*0.4 + (-1.23)*(-1.3) + 0.47*0.9)/2],


[(same as above), (0.4² + (-1.3)² + 0.9²)/2]]

Cov ≈ [[1.06, 1.04],


[1.04, 1.15]]
Step 3: Eigenvalues and Eigenvectors

We solve the eigenvalue problem:

Cov * v = λ * v
Let’s say we get:

Eigenvalues: [2.0, 0.2]


Eigenvectors:
PC1: [0.68, 0.73]
PC2: [-0.73, 0.68]
Step 4: Project the data

To reduce to 1D, we project the centered data onto the top eigenvector (PC1):

X_pca = X_centered · PC1


≈ [[0.77, 0.4] · [0.68, 0.73] = 0.77*0.68 + 0.4*0.73 = 0.84,
[-1.23, -1.3] · [0.68, 0.73] = -1.66,
[0.47, 0.9] · [0.68, 0.73] = 1.02]

Result

We have reduced the 2D data to 1D:

[0.84], [-1.66], [1.02]


This is the PCA-transformed data along the principal component!

You might also like