Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/notebooks/Chapter 13b - Principal Component Analysis.ipynb
Views: 449
data
is the feature data set, the columns are features with various terms of bonds. The matrices and share the same nonzero eigenvalues. This proposition is very powerful in the case that and are drastically different in size. For instance, if is , then there’s a quick way to find the eigenvalues of the matrix , first find the eigenvalues of (which is only 4 × 4). The other eigenvalues of are all zero!
We need to normalize the data, this makes sure that data with different unit or scale do not dominate.Eigenvalues and eigenvectors of the covariance matrix are used to determine the principal components in PCA.The eigenvectors provide the directions of the new feature space, and the eigenvalues indicate the importance of each direction.
Covariance matrix is diagonalized (specifically spectral decomposition as we discuss in chapter of Diagonalization)
Apply the theorem, and let be the eigenvalues of with corresponding eigenvectors .
These eigenvectors are the principal component of the data.
A fact we will need now: the sum of the eigenvalues is the trace of a symmetric matrix. It can be simply proved which used cyclic property of trace.
The trace of covariance matrix is the sum of variances, let's compute it.
It wouldn't surprise you, the trace equal , the number of features, because we have already normalized every feature, so the variance is for each feature, and the sum of variances will be the number of features, i.e. But also we have proved, the sum of eigenvalues should equal to the trace of a symmetric matrix, in our case a covariance matrix. Let's see if this is true.
Though a bit rounding errors in computation, the sum of eigenvalues should be equal to or sum of variances.
So the each principle accounts a percentage of total variance
We can show the cumulative sum of ratio, the first two principal account for of variances, we can reduce the data's dimensionality to two dimensions (using only the first two principal components) while preserving most of the information (variance).
Therefore we can reduce the orginal data's dimension by projecting original data onto principal components. This transformation creates a new dataset.
The transformation process is done by multiplying original data by matrix of eigenvectors
Now let's use sklearn library to perform the computation.
PCA Loadings
We need to define PCA factor loadings before further analysis. where and are diagonal matrix with eigenvalue and matrix of eigenvector accordingly. The factoring are scaled version of matrix of eigenvectors. It represents the contribution of each original variable to the principal components. They are scaled versions of the eigenvectors, making them more interpretable in terms of the variance explained by each component.