什么是“随机状态"?在sklearn.model_selection.train_test_split示例中? [英] What is "random-state" in sklearn.model_selection.train_test_split example?
问题描述
我真的是机器学习的新手,我正在通过 sklearn
I am really new to machine learning,i was going through some example on sklearn
在下面的示例中,有人可以解释一下随机状态"的真正含义吗?
Can someone explain me what really "Random-state" means in below example
import numpy as np
from sklearn.model_selection import train_test_split
X, y = np.arange(10).reshape((5, 2)), range(5)
X
list(y)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42)
X_train
y_train
X_test
y_test
为什么将其硬编码为42?
推荐答案
那不是很明显吗? 42是关于生命,宇宙和万物的终极问题的答案
Isn't that obvious? 42 is the Answer to the Ultimate Question of Life, the Universe, and Everything.
要特别注意的是,random_state
只是为随机生成器设置了一个种子,因此您的火车测试拆分始终是确定性的.如果您不设置种子,则每次都不同.
On a serious note, 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
实例或None
,可选 (默认=None
)
如果int
,则random_state
是随机变量使用的种子 数字生成器;如果RandomState
实例,则random_state
是随机变量 数字生成器;如果None
,则随机数生成器为np.random
使用的RandomState
实例.
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
.
这篇关于什么是“随机状态"?在sklearn.model_selection.train_test_split示例中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!