Issue
How to retrieve the random state of sklearn.model_selection.train_test_split
?
Without setting the random_state
, I split my dataset with train_test_split
. Because the machine learning model trained on the split dataset performs quite well, I want to retrieve the random_state
that was used to split the dataset. Is there something like numpy.random.get_state()
Solution
If you trace through the call stack of train_test_split
, you'll find the random_state
parameters is used like this:
from sklearn.utils import check_random_state
rng = check_random_state(self.random_state)
print(rng)
The relevant part of check_random_state
is
def check_random_state(seed):
if seed is None or seed is np.random:
return np.random.mtrand._rand
If random_state=None
, you get the default numpy.random.RandomState
singleton, which you can use to generate new random numbers, e.g.:
print(rng.permutation(10))
print(rng.randn(10))
See these questions for more information:
- Difference between np.random.seed() and np.random.RandomState()
- Consistently create same random numpy array
Answered By - mbatchkarov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.