我是初学者,RNNs
想GRU
为股票预测建立一个运行模型门控循环单元。
我有一个用于这种形状的训练数据的 numpy 数组:
train_x.shape
(1122,20,320)
`1122` represents the total amount timestamps I have `20` is the amount of timestamps I want to predict the future from `320` is the number of features (different stocks)
My is (1122,) 并用和train_y.shape
表示二进制变量。是买是卖。1
0
1
0
考虑到这一点,我开始尝试我的GRU
模型:
def GRU_model(train_x,train_y,test_x,test_y):
model = Sequential()
model.add(layers.Embedding(train_x.shape[0],50,input_length=320))
model.add(layers.GRU(50, return_sequences=True,input_shape=(train_x.shape[1],1),activation='tanh'))
model.add(layers.GRU(50, return_sequences=True,input_shape=(train_x.shape[1],1),activation='tanh'))
model.add(layers.GRU(50, return_sequences=True,input_shape=(train_x.shape[1],1),activation='tanh'))
model.add(layers.GRU(50,activation='tanh'))
model.add(Dense(units=2))
model.compile(optimizer=SGD(lr=0.01,decay=1e-7,momentum=0.9,nesterov=False),loss='mean_squared_error')
model.fit(train_x,train_y,epochs=EPOCHS,batch_size=BATCH_SIZE)
GRU_predict = model.predict(validation_x)
return model,GRU_predict
my_gru_model,my_gru_predict = GRU_model(train_x,train_y,validation_x,validation_y)
ValueError: Input 0 of layer gru_42 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 20, 320, 50)
显然我输入模型的尺寸不正确,但我不明白它们应该如何适应,所以模型可以顺利运行。