实现pca降维-Python实现
2021-04-22 00:28
标签:loading 参考 img class ret article ESS str div PCA:主成分分析-Python实现,X:[2500,784],把X降到50维 补: 参考: https://blog.csdn.net/baimafujinji/article/details/79407488 https://blog.csdn.net/qq_24464989/article/details/79834564?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase 实现pca降维-Python实现 标签:loading 参考 img class ret article ESS str div 原文地址:https://www.cnblogs.com/shuangcao/p/13278569.html 1 def pca(X=np.array([]), no_dims=50):
2 """
3 Runs PCA on the NxD array X in order to reduce its dimensionality to
4 no_dims dimensions.
5 """
6
7 print("Preprocessing the data using PCA...")
8 (n, d) = X.shape
9 X = X - np.tile(np.mean(X, 0), (n, 1)) # np.mean(X,0)在列上求均值
10 (l, M) = np.linalg.eig(np.dot(X.T, X))
11 Y = np.dot(X, M[:, 0:no_dims])
12 return Y
np.linalg.eig(np.dot(X.T, X)):
eig方法:计算方阵的特征值和右特征向量。
l:(784,):特征值
M:(784,784):右特征向量
Y = X*M