PRINCIPAL COMPONENT ANALYSIS (PCA)
Three-Subject Numerical Example of Dimensionality Reduction
1. Problem Statement
We have marks of five students in three subjects:
Mathematics, Physics and Chemistry.
PCA is used to transform the three original features into principal components
while preserving maximum variance.
2. Original Dataset
| Student | Mathematics | Physics | Chemistry |
|---|---|---|---|
| A | 2 | 1 | 5 |
| B | 4 | 3 | 4 |
| C | 6 | 5 | 8 |
| D | 8 | 7 | 6 |
| E | 10 | 9 | 10 |
3. PCA Calculation Process
PCA is performed through the following steps:
1. Calculate the mean
2. Center the data
3. Calculate the covariance matrix
4. Calculate eigenvalues
5. Calculate eigenvectors
6. Sort principal components
7. Calculate explained variance
8. Project the original data onto the principal component
1. Calculate the mean
2. Center the data
3. Calculate the covariance matrix
4. Calculate eigenvalues
5. Calculate eigenvectors
6. Sort principal components
7. Calculate explained variance
8. Project the original data onto the principal component
STEP 1
Calculate the Mean
Mean of Mathematics
Mean = (2 + 4 + 6 + 8 + 10) / 5 = 6
Mean of Physics
Mean = (1 + 3 + 5 + 7 + 9) / 5 = 5
Mean of Chemistry
Mean = (5 + 4 + 8 + 6 + 10) / 5 = 6.6
Mean Vector:
Mathematics = 6 | Physics = 5 | Chemistry = 6.6
Mathematics = 6 | Physics = 5 | Chemistry = 6.6
STEP 2
Center the Data
The mean of each feature is subtracted from every corresponding value.
Xcentered = X − Mean
| Student | Math − 6 | Physics − 5 | Chemistry − 6.6 |
|---|---|---|---|
| A | -4 | -4 | -1.6 |
| B | -2 | -2 | -2.6 |
| C | 0 | 0 | 1.4 |
| D | 2 | 2 | -0.6 |
| E | 4 | 4 | 3.4 |
Xc =
[ -4 -4 -1.6 ]
[ -2 -2 -2.6 ]
[ 0 0 1.4 ]
[ 2 2 -0.6 ]
[ 4 4 3.4 ]
[ -2 -2 -2.6 ]
[ 0 0 1.4 ]
[ 2 2 -0.6 ]
[ 4 4 3.4 ]
STEP 3
Calculate the Covariance Matrix
Covariance Matrix =
(1 / (n − 1)) XcTXc
Here, n = 5. Therefore:
n − 1 = 4
n − 1 = 4
Variance of Mathematics
Var(Math) =
[(-4)2 + (-2)2 + 02
+ 22 + 42] / 4
= 10
Variance of Physics
Var(Physics) = 10
Variance of Chemistry
Var(Chemistry) =
[2.56 + 6.76 + 1.96 + 0.36 + 11.56] / 4
= 5.8
Covariance Values
Cov(Math, Physics) = 10
Cov(Math, Chemistry) = 6
Cov(Physics, Chemistry) = 6
Final Covariance Matrix:
C =
[ 10 10 6 ]
[ 10 10 6 ]
[ 6 6 5.8 ]
[ 10 10 6 ]
[ 6 6 5.8 ]
STEP 4
Calculate the Eigenvalues
Eigenvalues are obtained by solving:
|C − λI| = 0
| 10−λ 10 6 |
| 10 10−λ 6 | = 0
| 6 6 5.8−λ |
| 10 10−λ 6 | = 0
| 6 6 5.8−λ |
λ1 ≈ 25.193
λ2 ≈ 0.607
λ3 = 0
Eigenvalues:
λ1 ≈ 25.193 | λ2 ≈ 0.607 | λ3 = 0
λ1 ≈ 25.193 | λ2 ≈ 0.607 | λ3 = 0
STEP 5
Calculate the Eigenvectors
The eigenvectors corresponding to the eigenvalues determine the
directions of the principal components.
Eigenvector for PC1
PC1 ≈
[ 0.645 ]
[ 0.645 ]
[ 0.410 ]
[ 0.645 ]
[ 0.410 ]
Eigenvector for PC2
PC2 ≈
[ 0.290 ]
[ 0.290 ]
[-0.912 ]
[ 0.290 ]
[-0.912 ]
Eigenvector for PC3
PC3 =
[ 0.707 ]
[-0.707]
[ 0.000 ]
[-0.707]
[ 0.000 ]
The signs of eigenvectors may be reversed without changing the PCA result.
What matters is the direction and variance represented by each component.
STEP 6
Sort the Principal Components
| Principal Component | Eigenvalue | Importance |
|---|---|---|
| PC1 | 25.193 | Highest |
| PC2 | 0.607 | Second |
| PC3 | 0 | Lowest |
STEP 7
Calculate Explained Variance
Total Variance =
25.193 + 0.607 + 0
= 25.800
Explained Variance of PC1 =
(25.193 / 25.800) × 100
≈ 97.65%
Explained Variance of PC2 =
(0.607 / 25.800) × 100
≈ 2.35%
Explained Variance of PC3 =
(0 / 25.800) × 100
= 0%
| Component | Eigenvalue | Explained Variance |
|---|---|---|
| PC1 | 25.193 | 97.65% |
| PC2 | 0.607 | 2.35% |
| PC3 | 0 | 0% |
PC1 contains approximately 97.65% of the total variance.
Therefore, the three original subjects can be represented very effectively
using only PC1.
STEP 8
Project Data onto PC1
The PCA value is obtained by multiplying each centered observation
by the PC1 eigenvector.
PC1 Score =
Xcentered × PC1 Eigenvector
Student A
PC1 = (-4 × 0.645) + (-4 × 0.645) + (-1.6 × 0.410)
≈ -5.166
Student B
PC1 = (-2 × 0.645) + (-2 × 0.645) + (-2.6 × 0.410)
≈ -2.355
Student C
PC1 = (0 × 0.645) + (0 × 0.645) + (1.4 × 0.410)
≈ 0.574
Student D
PC1 = (2 × 0.645) + (2 × 0.645) + (-0.6 × 0.410)
≈ 2.044
Student E
PC1 = (4 × 0.645) + (4 × 0.645) + (3.4 × 0.410)
≈ 5.017
9. Final Dataset with PCA Value
The original three subject columns are retained below for comparison,
and the newly calculated PC1 column is added.
| Student | Mathematics | Physics | Chemistry | PC1 |
|---|---|---|---|---|
| A | 2 | 1 | 5 | -5.166 |
| B | 4 | 3 | 4 | -2.355 |
| C | 6 | 5 | 8 | 0.574 |
| D | 8 | 7 | 6 | 2.044 |
| E | 10 | 9 | 10 | 5.017 |
10. Original Dataset vs PCA Dataset
| Original Features | Reduced Feature |
|---|---|
| Mathematics | PC1 |
| Physics | |
| Chemistry |
Dimensionality Reduction:
Original Dataset = 3 features
Reduced Dataset = 1 principal component
PC1 preserves approximately 97.65% of the total variance.
Original Dataset = 3 features
Reduced Dataset = 1 principal component
PC1 preserves approximately 97.65% of the total variance.
11. Final PCA Result
PCA DIMENSIONALITY REDUCTION
3 Original Subjects → 1 Principal Component
PC1 ≈ 97.65%
Most of the information contained in Mathematics,
Physics and Chemistry is represented by PC1.
12. Conclusion
PCA transforms the three correlated subject marks into new variables
called principal components.
PC1 captures approximately 97.65% of the total variance.
PC2 captures approximately 2.35% of the total variance.
PC3 captures 0% of the total variance.
Therefore, if approximately 97.65% information is sufficient,
the original three-dimensional dataset can be reduced to
one dimension using PC1.
13. PCA Summary
| Step | Result |
|---|---|
| Number of Original Features | 3 |
| Number of Students | 5 |
| Covariance Matrix | 3 × 3 |
| PC1 Eigenvalue | 25.193 |
| PC2 Eigenvalue | 0.607 |
| PC3 Eigenvalue | 0 |
| PC1 Variance | 97.65% |
| PC2 Variance | 2.35% |
| PC3 Variance | 0% |
| Reduced Dimension | 1 |
No comments:
Post a Comment