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)
cv = KFold(n_splits = 5, shuffle = True)
for tr_ix, te_ix in cv.split(X):
print (tr_ix, te_ix)
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)
cv = KFold(n_splits = 5, shuffle = True, random_state = 1)
for tr_ix, te_ix in cv.split(X):
print (tr_ix, te_ix)
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)
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)
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)
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)