python折叠次数计算珠穆朗玛峰_如何实现n次重复kfolds交叉验证,在sklearn中产生n*k个折叠?...

我很肯定他们在谈论RepeatedStratifiedKFold。你有两个简单的方法来创建5个折叠20次。在

方法1:

对于您的情况,n_splits=5, n_repeats=20。下面的代码只是scikit学习网站的示例。在from sklearn.model_selection import RepeatedStratifiedKFold

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

y = np.array([0, 0, 1, 1])

rskf = RepeatedStratifiedKFold(n_splits=2, n_repeats=2,

... random_state=42)

>>> for train_index, test_index in rskf.split(X, y):

... print("TRAIN:", train_index, "TEST:", test_index)

... X_train, X_test = X[train_index], X[test_index]

... y_train, y_test = y[train_index], y[test_index]

...

TRAIN: [1 2] TEST: [0 3] # n_repeats==1: the folds are [1 2] and [0 3]

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

TRAIN: [1 3] TEST: [0 2] # n_repeats==2: the folds are [1 3] and [0 2]

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

方法2:You can achieve the same effect with looping. Note that the random_state cannot be a fixed number, otherwise you will get the same 5 folds for 20 times.for i in range(20):

kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=i)

为什么它和你的代码不同?

假设你有10000个数据点,你创建了100个折叠。1倍的大小=100。您的培训集=9900,而验证集=100。在

RepeatedStratifiedKFold为您的模型创建5个折叠,每个折叠为2000。然后重复做5次折叠,再重复20次。这意味着您可以实现100倍,但是有一个非常大的验证集。根据您的目标,您可能需要一个更大的验证集,例如有足够的数据来正确验证,RepeatedStratifiedKFold使您能够以不同的方式创建相同数量的折叠(使用不同的训练验证比例)。除此之外,我不确定是否还有其他目标。

谢谢RepeatedStratifiedKFold。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值