-1

What's the significance of random_state=0 in this particular line??

X_train, X_test, y_train, y_test = train_test_split(X,  y, test_size = 0.25, random_state = 0)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 3
    Does this answer your question? [scikit-learn random state in splitting dataset](https://stackoverflow.com/questions/42191717/scikit-learn-random-state-in-splitting-dataset) – CodeAllDay Nov 27 '20 at 19:17

2 Answers2

1

Random state is a parameter to fix the way the data is being sampled. Therefore, if you want to reproduce the same model you choose any value for random_state and next time you run your code you will get the same data split.

Example you have a list1=[1,2,3,4] , let's say you can add to it a random_state for permutation, for random_state=0 the list1 will be [2,3,4,1], for random_state=2 it could be [3,1,4,2] etc... same thing for X_train X_test etc...

Each random number you input will give a different split.

ombk
  • 2,036
  • 1
  • 4
  • 16
0

random_state simply sets a seed to the random generator, so that your train-test splits are always deterministic. If you don't set a seed, it is different each time.

documentation:

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.

seralouk
  • 30,938
  • 9
  • 118
  • 133