Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"None of [Int64Index , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\n ...... dtype='int64')] are in the [columns]"

I'm currently trying to perform a KFold on my pandas data frame that reads a pandas file from csv. Unfortunately i'm getting the error:

"None of [Int64Index , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\n ...... dtype='int64')] are in the [columns]"

Here is my code:

def getSlicesOfData(read_csv):
    slice_training_data = read_csv[["player", "0", "1", "2", "3", "4", "5", "6", "7", "8"]]
    slice_prediction_data = read_csv[["best_move"]]
    return (slice_training_data, slice_prediction_data)

def getKFold(data_sliced):
    kf = KFold(n_splits=10, random_state=None, shuffle=False)
    return kf.split(data_sliced[0],data_sliced[1])
    #return TimeSeriesSplit(n_splits=10, max_train_size=9)

if __name__ == "__main__":
    read_csv = pd.read_csv('100games.csv')
    data_slice = getSlicesOfData(read_csv)
    for train_index, test_index in getKFold(data_slice):
        x_train, x_test = data_slice[0][train_index], data_slice[0][test_index]
        y_train, y_test = data_slice[1][train_index],data_slice[1][test_index]

what if anything am i doing wrong when attempting to get training data with:

x_train, x_test = data_slice[0][train_index], data_slice[0][test_index]
            y_train, y_test = data_slice[1][train_index],data_slice[1][test_index]
like image 554
plgent Avatar asked Nov 15 '25 01:11

plgent


1 Answers

You're trying to perform K-fold on pandas data frame and that's where the problem lies. Try to change the data structure from pandas to numpy instead and re-run back the code. At the end, you might want to change back your data structure from numpy to pandas.

like image 87
ssazally Avatar answered Nov 17 '25 22:11

ssazally



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!