0

I'm new to Python so this may have a very simple solution but I'm trying to implement the kFold Cross Validation algorithm.

To do this I split the test data into bins which I will then assign to test/train and test on for accuracy.

bins = np.array_split(indices, foldK)

Result of len(bins) is 5 and I can't imagine why the indexes would be something other than 0, 1, 2, 3, 4 but when I do:

for i in range(0,foldK):
    foldTrain=[] # list to save current indices for training
    foldTest=[]  # list to save current indices for testing
    print(i)
    foldTest = bins[i] #current index to test
    foldTrain = bins #rest of indexes to train
    foldTrain.pop(i)

I get an error "list index out of range" at foldTest = bins[i] on the 4th iteration, index 3.

0 Answers0