【发布时间】:2016-10-11 02:39:27
【问题描述】:
我正在学习 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)
【问题讨论】:
-
如果有人感兴趣,我可以通过像这样
X=X.reshape(X.shape[0],1,X.shape[1])重塑我的X值来解决问题