from sklearn.model_selection import KFold kf = KFold(n_splits=2) kf.split(df_train) step = 0 # set counter to 0 for train_index, val_index in kf.split(df_train): # for each fold step = step + 1 # update counter print('Step ', step) features_fold_train = df_train.iloc[train_index, [4, 5]] # features matrix of training data (of this step) features_fold_val = df_train.iloc[val_index, [4, 5]] # features matrix of validation data (of this step) target_fold_train = df_train.iloc[train_index, 6] # target vector of training data (of this step) target_fold_val = df_train.iloc[val_index, 6] # target vector of validation data (of this step) print("VALIDATE:", val_index) print('Dimensions features matrix for validation: ', features_fold_val.shape) print("TRAIN:", train_index) print('Dimensions features matrix for training: ',features_fold_train.shape, '\n')
further Information