pythonrandomscikit-learnsampling

What does the random_state parameter do in sklearn's ParameterSampler?


I am trying to implement sklearn's ParameterSampler, but I'm not completely sure what the random_state parameter does.

My guess is that if random_state is set to None, then normal random sampling is used. And if random_state is something other than None, then pseudo random sampling is used?

Also I'm not sure how different int values affect the sampling. For example, is random_state = 1 different form random_state = 2? If yes, how?


Solution

  • From the documentation:

    If random_state is None or np.random, then a randomly-initialized RandomState object is returned.

    If random_state is an integer, then it is used to seed a new RandomState object.

    If random_state is a RandomState object, then it is passed through.

    Basically, by setting the random_state, you guarantee that the (pseudo-) random number generator generates the same sequence of random integers each time, which in turn has an effect on the way your data is sampled.