Keras:ValueError:检查inpu时出错

2024-03-28 12:29:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样一个长度为7499042的熊猫数据帧:

'X'          'y'
[0.1,0.2...] 0.2
[0.3,0.4,..] 0.3
.
.

pandas数据帧中的每个值都是长度为50的numpy数组。 现在我这样提取:

^{pr2}$

我有这样的层次:

main_input = Input(shape=(50,1), name='main_input')    
lstm_out=LSTM(32,activation='tanh',recurrent_activation='sigmoid',return_sequences=True)
mean_pooling=AveragePooling1D(pool_size=2,strides=2,padding='valid')

但是当我在训练的时候把我的意见传递给他们。显示错误:

ValueError: Error when checking input: expected main_input to have 3 dimensions, but got array with shape (7499042, 1)

它显示的输入的形状是(7499042,)。请帮我解决这个问题。在


Tags: 数据namenumpypandasinputmain数组out
1条回答
网友
1楼 · 发布于 2024-03-28 12:29:06

在将特征输入LSTM网络之前,您需要重新调整特性。 LSTM层采用三维输入,对应于(批处理大小、时间步长、特性)。这意味着单个观测必须是二维的(时间步长、特征)

在您的例子中,单个观察值是一维(50,):如果转换正确,整个数据集维度是:(7499042,50)。 在使用输入之前,您必须重新调整输入:

input = df['X'].values
input = input.reshape(input.shape[0] , input.shape[1] , 1)

如果Pandas没有将您的初始特性转换为2d数据帧,您必须在执行上述代码之前执行该操作。在

相关问题 更多 >