我正在尝试对有两个输入变量的数据进行时间序列分析,即时间戳和学生没有。在拟合LSTM模型时,我得到以下错误“检查输入时出错:预期lstm_40_input有3个维度,但是在model.fit()上得到了具有形状的数组(69452,1)”。我是keras的新手,我仍然很困惑如何适应模型。我的数据是形式(69452,1,1),即三维向量。
以下是代码:
trainX, trainY = createDataSet(train)
testX, testY = createDataSet(test)
trainY=trainY.reshape(69452,1)
testY=testY.reshape(140,1)
trainX=trainX.reshape(69452,1)
testX=testX.reshape(140,1)
xTrain = np.reshape(trainX, (trainX.shape[0],1, trainX.shape[1]))
xTest = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))
yTrain = np.reshape(trainY, (trainY.shape[0],1, trainY.shape[1]))
yTest = np.reshape(testY, (testY.shape[0], 1, testY.shape[1]))
yTrain = np.reshape(trainY, (trainY.shape[0], 1, trainY.shape[1]))
yTest = np.reshape(testY, (testY.shape[0], 1, testY.shape[1]))
model = Sequential()
model.add(LSTM(4, input_shape=(1, look_back)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(xTrain , yTrain , epochs=100, batch_size=1, verbose=2)