编程语言
首页 > 编程语言> > python-RepeatedKFold实际上是什么意思?

python-RepeatedKFold实际上是什么意思?

作者:互联网

假设n_repeats = 5,折叠数为3(n_splits = 3).

这是否意味着验证者正在为我们的估算器/模型创建3折以使用每一折(例如KFold的用途),然后将该过程重复5次?

这意味着我们的模型将总共使用5 x 3 = 15倍?

解决方法:

是的,您基本上可以通过循环调用KFolds.split()n_repeats次来达到相同的效果.

设置示例:

X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]])
y = np.array([0, 0, 1, 1])

然后运行:

rkf = RepeatedKFold(n_splits=2, n_repeats=1, random_state=2652124)
for train_index, test_index in rkf.split(X):
  print("TRAIN:", train_index, "TEST:", test_index)

…产生:

TRAIN: [0 1] TEST: [2 3]
TRAIN: [2 3] TEST: [0 1]

…就像KFold(n_splits = 2,random_state = 2652124)一样.更改为n_repeats = 2会产生:

TRAIN: [0 1] TEST: [2 3]
TRAIN: [2 3] TEST: [0 1]
TRAIN: [1 2] TEST: [0 3]
TRAIN: [0 3] TEST: [1 2]

等等.

标签:cross-validation,scikit-learn,data-science,machine-learning,python
来源: https://codeday.me/bug/20191109/2012630.html