Mastering PCA: Eigenvectors, Eigenvalues, and Covariance Matrix Explained
Introduction
Embark on an exciting journey through the world of Principal Component Analysis (PCA). We will explore the indispensable roles of Eigenvalues and Eigenvectors in understanding PCA framework, and dive into the computation of these mathematical constructs using Python. Our adventure will cover the essential role of the Covariance Matrix and how to compute it. Ready? Set? Let's start!
Collecting Data
At the onset, we start with a dataset housing different physical measures - weight (in lbs), height (in inches), and height (in cm). We capture these in a Python dictionary, convert it to a pandas DataFrame for easy manipulation:
Here, the DataFrame, df, represents our collected dataset.
Introduction to Standardization
Before performing Principal Component Analysis, we need to standardize the data. This just means changing the scale of our data so each feature has a mean of 0 and a standard deviation of 1.
PCA is sensitive to the scale of the features. Features with larger scales will dominate the variance calculations and may bias the results towards those features. Standardizing the data ensures that each feature contributes equally to the analysis, preventing this bias.
To standardize the data, each feature is transformed using the following formula:
Where:
- is the standardized value of the feature.
- is the original value of the feature.
- is the mean of the feature.
- is the standard deviation of the feature.
Let's standardize just the 2 height columns in our dataset:
After standardization, our data is now centered and scaled, making variables more comparable.


