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)
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)
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.
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.
random_state
:int
,RandomState
instance orNone
, optional (default=None
)
Ifint
,random_state
is the seed used by the random number generator; IfRandomState
instance,random_state
is the random number generator; IfNone
, the random number generator is theRandomState
instance used bynp.random
.