Factor Loadings using sklearn

非 Y 不嫁゛ 提交于 2019-11-30 00:07:08

I think that @RickardSjogren is describing the eigenvectors, while @BigPanda is giving the loadings. There's a big difference: Loadings vs eigenvectors in PCA: when to use one or another?.

I created this PCA class with a loadings method.

Loadings, as given by pca.components_ * np.sqrt(pca.explained_variance_), are more analogous to coefficients in a multiple linear regression. I don't use .T here because in the PCA class linked above, the components are already transposed. numpy.linalg.svd produces u, s, and vt, where vt is the Hermetian transpose, so you first need to back into v with vt.T.

There is also one other important detail: the signs (positive/negative) on the components and loadings in sklearn.PCA may differ from packages such as R. More on that here:

In sklearn.decomposition.PCA, why are components_ negative?.

RickardSjogren

According to this blog the rows of pca.components_ are the loading vectors. So:

loadings = pca.components_
BigPanda

Multiply each component by the square root of its corresponding eigenvalue:

pca.components_.T * np.sqrt(pca.explained_variance_)

This should produce your loading matrix.

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