在 random.sample 中的随机状态

4

我正在编写自定义GridSearchCV的代码。每次执行代码时,我希望选择和随机排列indies(索引)。但是我无法弄清如何将种子函数实现到其中。以下是我的代码片段,请告诉我是否需要进行任何添加。

代码:

train_indices=random.sample(range(0,len(x_train)),int(folds_percent*len(x_train)))
test_indices=list(set(list(range(1,len(x_train))))-set(train_indices))

感谢您的帮助!|:-)


1
似乎你需要使用random.seed()来完成这个任务。请参考https://docs.python.org/2/library/random.html。 - Joe
1个回答

3
在调用random.sample()之前,使用random.seed()命令:
random.seed(41)
random.sample([1,2,3,4,5], k=2)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接