sklearn PCA.transform gives different results for different trials

后端 未结 2 1127
傲寒
傲寒 2021-01-07 13:56

I am doing some PCA using sklearn.decomposition.PCA. I found that if the input matrix X is big, the results of two different PCA instances for PCA.transform will not be the

相关标签:
2条回答
  • 2021-01-07 14:14

    I had a similar problem even with the same trial number but on different machines I was getting different result setting the svd_solver to 'arpack' solved the problem

    0 讨论(0)
  • 2021-01-07 14:23

    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)
    
    0 讨论(0)
提交回复
热议问题