gpt4 book ai didi

python - Pandas - KeyError : '[] not in index' when training a Keras model

转载 作者:太空狗 更新时间:2023-10-29 18:29:23 29 4
gpt4 key购买 nike

我正在尝试根据我的数据集中的部分特征训练 Keras 模型。我已经加载了数据集并提取了如下特征:

train_data = pd.read_csv('../input/data.csv')

X = train_data.iloc[:, 0:30]
Y = train_data.iloc[:,30]

# Code for selecting the important features automatically (removed) ...

# Selectintg important features 14,17,12,11,10,16,18,4,9,3
X = train_data.reindex(columns=['V14','V17','V12','V11','V10','V16','V18','V4','V9','V3'])
print(X.shape[1]) # -> 10

但是当我调用 fit 方法时:

# Fit the model
history = model.fit(X, Y, validation_split=0.33, epochs=10, batch_size=10, verbose=0, callbacks=[early_stop])

我收到以下错误:

KeyError: '[3 2 5 1 0 4] not in index'

我错过了什么?

最佳答案

keras 期望模型输入是 numpy 数组 - 而不是 pandas.DataFrame。尝试:

X = train_data.iloc[:, 0:30].as_matrix()
Y = train_data.iloc[:,30].as_matrix()

As as_matrix 方法将 pandas.DataFrame 转换为 numpy.array

关于python - Pandas - KeyError : '[] not in index' when training a Keras model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45479239/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com