0
$\begingroup$

I have been using sklearn for quite some time and I understand using the same number say 100 or 200 as a value for the random_state argument will help me to produce the similar train and test data sets. However, how does it work?

Is it some kind of initialization? Do we need to pick a value based on data size? I want to know how random_state works.

$\endgroup$
2
$\begingroup$

In the documentation (for example for KFold) you can find the following explanation:

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 shuffle == True.

Obviously, the way you use it falls into the first use case. Thus, the number is used as a seed for the pseudorandom number generator. When you have the seed hardcoded as a parameter, you use the same seed for a second time. This will result in the same sequence of pseudorandom numbers, thus not random at all. Because of this, use numeric seeds only for testing purposes when you want to reproduce your "randomness". For learning experiments and production purposes, you can just leave the default None value.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.