3
votes

I am using PCA to visualize clusters and noticed Sklearn added "random_state" parameter to the PCA method (http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html), my question is what does the random_state parameter do there?

My understanding is that PCA should return the same principle components despite the random state, so, what is the purpose of having it built in?

1

1 Answers

2
votes

As the docs state, this param is only relevant for some of the solvers:

random_state : int, RandomState instance or None, optional (default None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when svd_solver == ‘arpack’ or ‘randomized’.

The randomized solver is described in Finding Structure With Randomness: Stochastic Algorithms For Constructing Approximate Matrix Decompositions and it's clear that it's an approximation with guaranteed error-bounds.

Now what's with arpack? It's an iterative method and wiki's pseudo-code already shows some random-initialization and the arpack-page also mentions Implicitly Restarted Arnoldi Method, where restart is one more indication of randomness.

So be prepared to see, that not all methods output the same result. arpack and especially randomized are targeting bigger datasets, where approximation is all we can do.

Also observe, that both of these solvers were not available in version 0.17 when there was no random_state parameter.