k折交叉验证时x与y维度不一致

在使用train_test_split分割数据集之后,x_train和y_train的维度还是一样的,但是经过k折交叉验证之后kf_x_train和kf_y_train的维度就变得不一致了,代码如下:

img

运行结果如下图所示

img

求解答,我已经被困扰好几天了!!

shuffle 打乱顺序了 索引也会变的, 要么重置索引 要么不用shuffle 默认是False 好像

或者应该

for train_index, test_index in skf.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]