使用keras LSTM图层进行预测

时间:2017-09-26 16:31:22

标签: python keras keras-layer

我是python的新手,特别是“keras(2)”库,我很难为以下问题创建回归lstm模型:

我正在努力优化与股市相关的业绩。培训数据为595种库存,每种库存179个特征,每个库存3000个时间样本。总计595x179x3000。 首先,通过将595个股票连接在一起来处理数据,以形成179个特征中每个特征的尺寸数据库矩阵179x1785000 - 1785000个时间样本。

由于“initial_epoch”字段,拟合未完成。 程序似乎进入了一个无限循环。如果您对我当前的问题有任何建议或任何其他有关我尝试解决问题的未来问题,请告诉我们。

相关代码:

from keras.layers.core import Dense
from keras.layers.recurrent import LSTM
from keras.models import Sequential
import time
import scipy.io


# x is 1785000x179 matrix
# y is 1785000x1 training target vector with values in                              
# the interval [-1.5,1.5] 

# Model design
model = Sequential()

# First layer
model.add(LSTM(units = 20, batch_size = 5000, input_shape = (1785000,179), 
activation = 'relu', dropout = 0.2, return_sequences = True))


# Second layer
model.add(LSTM(units = 15, activation = 'relu', dropout = 0.1, 
return_sequences = True))

# Third layer
model.add(LSTM(units = 5, activation = 'relu', return_sequences = True))

# Fourth layer
model.add(Dense(output_dim = 179, activation = 'linear' ))

# Compilation
model.compile(loss = 'mse',optimizer = 'rmsprop')

# Training
model.fit(x, y, batch_size = 5000, epochs = 2, verbose = 1)


# Testing
# predicting the 1638 target values for the 595 stocks,  
# one 1x1638 vector at a time 
for k in range(595):
    x_test = (database['features'][k][3000:4638])
    y_test.append(model.predict(x_test))

0 个答案:

没有答案