import numpy as np
# 随机产生我们的数据集
x = np.random.randint(-10, 10, 10)
y = (x > 0).astype(int)
k = 2 # 2折验证法
num_val_samples = 1 # 定义我们的个数
for i in range(k):
print('processing fold #', i)
test_x = x[i * num_val_samples: (i + 1) * num_val_samples]
test_y = y[i * num_val_samples: (i + 1) * num_val_samples]
#当i为1时,我们的train取到的应该是第0列和第2列之后的,所以进行数据的堆叠
train_x = np.concatenate(
[x[:i * num_val_samples],
x[(i + 1) * num_val_samples:]],
axis=0)
train_y = np.concatenate(
[y[:i * num_val_samples],
y[(i + 1) * num_val_samples:]],
axis=0)
print(test_x)
print(train_x)
结果: