【问题标题】:Whats the significance of random_state in train_test_split? [duplicate]train_test_split中random_state的意义是什么? [复制]
【发布时间】:2021-03-10 13:07:17
【问题描述】:

random_state=0 在这一行有什么意义??

X_train, X_test, y_train, y_test = train_test_split(X,  y, test_size = 0.25, random_state = 0)

【问题讨论】:

标签: python scikit-learn


【解决方案1】:

随机状态是固定数据采样方式的参数。因此,如果您想重现相同的模型,您可以为 random_state 选择任何值,下次运行代码时,您将获得相同的数据拆分。

示例 你有一个 list1=[1,2,3,4] ,假设你可以添加一个 random_state 进行排列,对于 random_state=0,list1 将是 [2,3,4,1],对于 random_state=2 它可能是 [3,1,4,2] 等等......同样的事情X_trainX_test等等……

您输入的每个随机数都会给出不同的拆分。

【讨论】:

    【解决方案2】:

    random_state 只需为随机生成器设置一个种子,以便您的训练测试拆分始终是确定性的。不种下种子,每次都不一样。

    documentation:

    random_state : intRandomState 实例或None,可选 (默认=None
    如果intrandom_state是随机使用的种子 数字生成器;如果RandomState 实例,random_state 是随机的 数字生成器;如果None,随机数生成器是 RandomStatenp.random 使用的实例。

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 2018-09-21
      • 2018-01-19
      • 2017-03-22
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-18
      • 2012-01-10
      相关资源
      最近更新 更多