爽歪歪666
不以物喜,不以己悲,努力才是永恒的主题。

PCA:主成分分析-Python实现,X:[2500,784],把X降到50维

 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

补:

参考:

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

 

 





posted on 2020-07-10 12:02  爽歪歪666  阅读(405)  评论(0编辑  收藏  举报