Derivation of PCA Using Linear Algebra
PCA seeks a new set of axes, called principal components, such that the projected data has maximum variance. The first principal component, denoted as w1ββ, is chosen to maximize the variance of the projected data:
Var(Xw1β)Subject to the constraint that β₯w1βββ₯=1. The solution to this maximization problem is the eigenvector of the covariance matrix corresponding to the largest eigenvalue.
The optimization problem is:
wmaxβΒ wTΞ£wsubjectΒ toβ₯wβ₯=1The solution is any vector w that satisfies Ξ£w=Ξ»w, where Ξ» is the corresponding eigenvalue. In other words, w is an eigenvector of the covariance matrix Ξ£ associated with eigenvalue Ξ».
12345678910111213import numpy as np # Assume cov_matrix from earlier X = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9]]) X_centered = X - np.mean(X, axis=0) cov_matrix = (X_centered.T @ X_centered) / X_centered.shape[0] # Find the principal component (eigenvector with largest eigenvalue) values, vectors = np.linalg.eig(cov_matrix) principal_component = vectors[:, np.argmax(values)] print("First principal component:", principal_component)
This principal component is the direction along which the data has the highest variance. Projecting data onto this direction gives the most informative one-dimensional representation of the original dataset.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain why the principal component is important in PCA?
How do I interpret the values of the principal component?
What does projecting data onto the principal component mean?
Awesome!
Completion rate improved to 8.33
Derivation of PCA Using Linear Algebra
Swipe to show menu
PCA seeks a new set of axes, called principal components, such that the projected data has maximum variance. The first principal component, denoted as w1ββ, is chosen to maximize the variance of the projected data:
Var(Xw1β)Subject to the constraint that β₯w1βββ₯=1. The solution to this maximization problem is the eigenvector of the covariance matrix corresponding to the largest eigenvalue.
The optimization problem is:
wmaxβΒ wTΞ£wsubjectΒ toβ₯wβ₯=1The solution is any vector w that satisfies Ξ£w=Ξ»w, where Ξ» is the corresponding eigenvalue. In other words, w is an eigenvector of the covariance matrix Ξ£ associated with eigenvalue Ξ».
12345678910111213import numpy as np # Assume cov_matrix from earlier X = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9]]) X_centered = X - np.mean(X, axis=0) cov_matrix = (X_centered.T @ X_centered) / X_centered.shape[0] # Find the principal component (eigenvector with largest eigenvalue) values, vectors = np.linalg.eig(cov_matrix) principal_component = vectors[:, np.argmax(values)] print("First principal component:", principal_component)
This principal component is the direction along which the data has the highest variance. Projecting data onto this direction gives the most informative one-dimensional representation of the original dataset.
Thanks for your feedback!