import numpy as np
from sklearn.model_selection import KFold
Y = np.array([[1, 2], [3, 4], [5, 6], [7, 8],[9,10],[11,12]])
i=0
kf = KFold(n_splits=3)
#3折交叉验证,将数据分为三份,每次取一份作为test集
for train_index, test_index in kf.split(Y):
i=i+1
print(i)
print('train_index', train_index, 'test_index', test_index)
#train_index与test_index为下标
train_Y = Y[train_index]
test_Y= Y[test_index]