Skip to content Skip to sidebar Skip to footer

How To Retrieve The Random_state Of Sklearn.model_selection.train_test_split?

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 learni

Solution 1:

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

defcheck_random_state(seed):
    if seed isNoneor 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:

Solution 2:

What do you mean?

If you wanna know which random_state you are using, you have to use random_state while running the function, for example:

X_train, X_test, y_train, y_test = train_test_split(
...    X, y, test_size=0.33, random_state=42)

by default its set to none see the docs.

Here are also further information to random_state.

Or do you mean this?

Post a Comment for "How To Retrieve The Random_state Of Sklearn.model_selection.train_test_split?"