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.
フィードバックありがとうございます!
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください