【发布时间】:2018-03-10 01:13:39
【问题描述】:
我在几个预测任务中应用 CV,并且希望始终对我的每个参数集使用相同的折叠 - 如果可能的话,也可以在不同的 python 脚本中使用,因为性能确实取决于折叠。 我正在使用 sklearns KFold:
kf = KFold(n_splits=folds, shuffle=False, random_state=1986)
并通过
构建我的折叠for idx_split, (train_index, test_index) in enumerate(kf.split(X, Y)):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = Y[train_index], Y[test_index]
然后像这样循环遍历它们
for idx_alpha, alpha in enumerate([0, 0.2, 0.4, 0.6, 0.8, 1]):
# [...]
for idx_split, (train_index, test_index) in enumerate(kf.split(X, Y)):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = Y[train_index], Y[test_index]**
虽然我选择了一个 random_state 并设置了一个 numpy 种子,但折叠并不总是相等。我可以做些什么来实现这一点,并可能通过几个 python 脚本共享我的折叠?
【问题讨论】:
标签: python scikit-learn