How to get the 1st Principal Component by PCA using Python?

元气小坏坏 提交于 2019-11-29 17:20:34

PCA gives only 2d vecs from 2d data.

Look at the picture in Wikipedia PCA:
starting with a point cloud (dataMatrix) like that, and using matplotlib.mlab.PCA,
myPCA.Wt[0] is the first PC, the long one in the picture.

Nicolas Barbey

It isn't obvious from your example that you are using matplotlib.mlab.PCA but if so, the documentation states that the returned object has an attribute Wt, which is "the weight vector for projecting a numdims point or array into PCA space".

PCA returns the eigenvalues in descending order (you can tell by looking at the fracs attribute of the returned object). So the first principal component (first eigenvector) will be the first row of Wt.

As noted by @denis, your eigenvectors will be 2D (not 3D) since your input data are 2D.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!