我正在学习RNN,我使用sklearn生成的样本数据集在keras(theano)中编写了这个简单的LSTM模型 .
from sklearn.datasets import make_regression
from keras.models import Sequential
from keras.layers import Dense,Activation,LSTM
#creating sample dataset
X,Y=make_regression(100,9,9,2)
X.shape
Y.shape
#creating LSTM model
model = Sequential()
model.add(LSTM(32, input_dim=9))
model.add(Dense(2))
model.compile(loss='mean_squared_error', optimizer='adam')
#model fitting
model.fit(X, Y, nb_epoch=1, batch_size=32)
样本数据集包含9个要素和2个目标 . 当我尝试使用这些功能和目标来适应我的模型时,它给了我这个错误
Exception: Error when checking model input: expected lstm_input_9 to have 3 dimensions, but got array with shape (100, 9)
1 回答
如果我是正确的,那么LSTM期望3D输入 .
UPDATE :如果您想将
X, Y = make_regression(100, 9, 9, 2)
转换为3D,那么您可以使用它 .