1

When I use train_test_splid as:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test =train_test_split(X, Y, test_size = 0.9)

If I do not set specific random_state. how to get the current random seed the program use?

MarioKZZ
  • 141
  • 2
  • 8
  • 1
    why not set it yourself? something like `random_state = 3`? each time you dont set it yourself it will use different seed. Note that you should set `shuffle` as well. cause according to [documentation](https://scikit-learn.org/stable/glossary.html#term-random_state) , randomization might depend on shuffle as well – Me Bottle O Scrumpy Apr 24 '21 at 12:07
  • Could you explain any reason why not set yourself ? – Aditya Singh Rathore Apr 24 '21 at 12:21

2 Answers2

1

The fundamental thing here is the random state. You can generate random states from seeds. But if you do not specify a seed there is no seed, just a random state. Which you can access if you want:

sklearn.utils.check_random_state()

or

np.random.get_state()

You could then later pass the random state object to

np.random.set_state(state)

Also see this question. You really can't get the seed without setting it first in some way.

examiner
  • 156
  • 6
0

From their documentation

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

You can use check_random_state

If you need a Random state,you should initialize it by yourself.