在train_test_split sklearn python上设置种子



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

预先感谢。

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_testrongplit。

仅在train_test_split中,指定参数random_state=some_number_you_wan to use,,例如random_state=42

最新更新