numpy random seed vs. sklean random_state

import numpy as np
from sklearn.model_selection import KFold
random_seed = 1
np.random.seed(random_seed)
X = range(10)

No random_state

cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 2 3 4 7 8 9] [5 6]
[0 1 2 3 5 6 7 9] [4 8]
[0 1 3 4 5 6 7 8] [2 9]
[1 2 4 5 6 7 8 9] [0 3]
[0 2 3 4 5 6 8 9] [1 7]
cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 2 3 4 5 7 9] [6 8]
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 4 5 6 7 8] [3 9]
[1 2 3 4 6 7 8 9] [0 5]
[0 1 3 5 6 7 8 9] [2 4]

With random_state

cv = KFold(n_splits = 5, shuffle = True, random_state = 1)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 3 4 5 6 7 8] [2 9]
[0 1 2 3 5 7 8 9] [4 6]
[1 2 4 5 6 7 8 9] [0 3]
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 3 4 6 7 9] [5 8]
cv = KFold(n_splits = 5, shuffle = True, random_state = 1)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 3 4 5 6 7 8] [2 9]
[0 1 2 3 5 7 8 9] [4 6]
[1 2 4 5 6 7 8 9] [0 3]
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 3 4 6 7 9] [5 8]

Using np.random.seed

np.random.seed(1)
cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 3 4 5 6 7 8] [2 9]
[0 1 2 3 5 7 8 9] [4 6]
[1 2 4 5 6 7 8 9] [0 3]
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 3 4 6 7 9] [5 8]

Without either random seed or random state

cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 1 2 3 4 6 7 8] [5 9]
[1 2 4 5 6 7 8 9] [0 3]
[0 1 2 3 5 6 7 9] [4 8]
[0 3 4 5 6 7 8 9] [1 2]
[0 1 2 3 4 5 8 9] [6 7]

Equivalence

cv = KFold(n_splits = 5, shuffle = True, random_state = 19)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 3 4 5 7 8] [6 9]
[0 1 2 3 5 6 7 9] [4 8]
[1 2 4 5 6 7 8 9] [0 3]
[0 1 3 4 6 7 8 9] [2 5]
np.random.seed(19)
cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
    print (tr_ix, te_ix)
[0 2 3 4 5 6 8 9] [1 7]
[0 1 2 3 4 5 7 8] [6 9]
[0 1 2 3 5 6 7 9] [4 8]
[1 2 4 5 6 7 8 9] [0 3]
[0 1 3 4 6 7 8 9] [2 5]