“没有 [Int64Index , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\n ...... dtype='int64 ')] 位于 [列] 中”

2024-01-08

我目前正在尝试对 pandas 数据框执行 KFold,从 csv 读取 pandas 文件。不幸的是我收到错误:

“没有 [Int64Index , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\n ...... dtype='int64 ')] 位于 [列] 中”

这是我的代码:

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]

如果我在尝试获取训练数据时做错了什么:

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]

您正在尝试对 pandas 数据框执行 K-fold,这就是问题所在。尝试将数据结构从 pandas 更改为 numpy,然后重新运行代码。最后,您可能希望将数据结构从 numpy 更改回 pandas。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“没有 [Int64Index , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\n ...... dtype='int64 ')] 位于 [列] 中” 的相关文章

随机推荐