sklearn PCA.transform gives different results for different trials

别来无恙 提交于 2019-12-01 01:59:19

There's a svd_solver param in PCA and by default it has value "auto". Depending on the input data size, it chooses most efficient solver.

Now as for your case, when size is larger than 500, it will choose randomized.

svd_solver : string {‘auto’, ‘full’, ‘arpack’, ‘randomized’}

auto :

the solver is selected by a default policy based on X.shape and n_components: if the input data is larger than 500x500 and the number of components to extract is lower than 80% of the smallest dimension of the data, then the more efficient ‘randomized’ method is enabled. Otherwise the exact full SVD is computed and optionally truncated afterwards.

To control how the randomized solver behaves, you can set random_state param in PCA which will control the random number generator.

Try using

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