gpt4 book ai didi

python-3.x - 在 train_test_split sklearn python 上设置种子

转载 作者:行者123 更新时间:2023-12-04 11:22:15 26 4
gpt4 key购买 nike

有什么方法可以在 python sklearn 上的 train_test_split 上设置种子。我已经设置了参数 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_test_split。

关于python-3.x - 在 train_test_split sklearn python 上设置种子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56166130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com