【问题标题】:Setting seed on train_test_split sklearn python在 train_test_split sklearn python 上设置种子
【发布时间】:2019-10-03 14:07:51
【问题描述】:

有没有办法在 python sklearn 上的 train_test_split 上设置种子。我已将参数random_state 设置为整数,但仍然无法重现结果。

提前致谢。

【问题讨论】:

    标签: python-3.x scikit-learn jupyter-notebook train-test-split


    【解决方案1】:
    from sklearn.model_selection import train_test_split
    x = [k for k in range(0, 10)]
    y = [k for k in range(0, 10)]
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4, random_state=11)
    print (x_train)
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4, random_state=11)
    print (x_train)
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4, random_state=11)
    print (x_train)
    

    每次我拆分数据时,上面的代码都会为 x_train 产生相同的结果。随机性可能在您的数据框中,而不是 train_test_split。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 2020-03-18
      • 2019-03-25
      相关资源
      最近更新 更多