如何解决rNN中的值错误?

时间:2019-05-23 10:50:25

标签: python keras recurrent-neural-network

当我做rNN时,我得到了:ValueError:检查输入时出错:预期lstm_2_input具有3维,但是数组的形状为(99,20)

scaler = MinMaxScaler(feature_range=(0, 1))
data = scaler.fit_transform(data)

time_window = 20

Xall, Yall = [], []
for i in range(time_window, len(data)):
    Xall.append(data[i-time_window:i, 0])
    Yall.append(data[i, 0])
Xall = np.array(Xall)   
Yall = np.array(Yall)
train_size = int(len(Xall) * 0.8)
test_size = len(Xall) - train_size
Xtrain = Xall[:train_size, :]
Ytrain = Yall[:train_size]
Xtest = Xall[-test_size:, :]
Ytest = Yall[-test_size:]

model = Sequential()
model.add(LSTM(input_shape =     (None,1),units=50,return_sequences=False))
model.add(Dense(output_dim=1))
model.add(Activation("linear"))
model.compile(loss="mse", optimizer="rmsprop")

from keras.callbacks import EarlyStopping
early_stop = EarlyStopping(monitor='loss', patience=2,verbose=1)
   model.fit(Xtrain,Ytrain,batch_size=5,nb_epoch=20,validation_split=0.1)

allPredict = model.predict(np.reshape(Xall,(124,20,1)))

Xtrain has a size of (99, 20), while for Ytrain is (99,). I don't know where is wrong.

0 个答案:

没有答案