LSTM预测中形状错误

我已经训练了一个模型:

trainX = trainX.reshape(1, 43164, 17)trainY = trainY.reshape(43164, 1)model = Sequential()model.add(LSTM(2, input_shape=(43164, 17)))model.add(Dense(1))model.compile(loss='mean_squared_error', optimizer='adam')model.fit(trainX, trainY[0], epochs=100)testX.shape # (8633, 17)testX = testX.reshape(1, 8633, 17)

当我对这些数据进行预测时,我得到了一个错误:

Error when checking input: expected lstm_26_input to have shape (43164, 17) but got array with shape (8633, 17)

我应该做些什么才能获得好的结果?


回答:

在深度学习网络的序列模型中,您可以使用有限的短窗口和改变窗口的步长来传递数据,或者

传递一个由一维向量组成的完整序列

trainX = trainX.reshape( 43164,1, 17)trainY = trainY.reshape(43164, 1)model = Sequential()model.add(LSTM(2, input_shape=(1, 17)))model.add(Dense(1))model.compile(loss='mean_squared_error', optimizer='adam')model.fit(trainX, trainY[0], epochs=100)testX.shape # (8633, 17)testX = testX.reshape(8633,1, 17)

Related Posts

Flatten and back keras

我正在尝试使用自编码器获取简单向量中的值 这是我的代码…

如何按索引访问PyTorch模型参数

如果我的网络有10层,包括偏置项,如何仅通过索引访问第…

Python中多元逻辑回归显示错误

我试图使用逻辑回归进行预测,并使用Python和skl…

在MACOS上安装NLTK

我在我的2015款Mac Pro上尝试安装NLTK,操…

如何在R中将通过RFE选择的变量插入到机器学习模型中?

我想使用递归特征消除方法来选择最重要的特征,然后将这些…

CountVectorizer 错误:ValueError: setting an array element with a sequence

我有一个包含144条学生反馈的数据集,其中有72条正面…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注