在train_test_split sklearn python

时间:2019-05-16 10:12:24

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

有什么方法可以在python sklearn的train_test_split上设置种子。我已经将参数random_state设置为整数,但是仍然无法重现结果。

谢谢。

1 个答案:

答案 0 :(得分:0)

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。