python - 向 LSTM RNN 添加新功能
问题描述
我有一个神经网络的基本示例,它目前接受一段时间内的价格。我想添加一条支持信息,即模型要考虑的税款清单。
我正在努力以模型可以接受的方式排列我的数据。
你能告诉我如何让这个例子接受一个额外的特性并考虑这些新数据吗?谢谢你。
完整代码如下,复制粘贴即可。
import numpy as np
from keras.models import Sequential #, LSTM
from keras.layers.core import Dense;
from keras.layers import LSTM
import tensorflow as tf
time_list = [ 1296000.0, 19350000.0, 29635200.0, 48294000.0, 45961200.0] # time in milliseconds since an arbitrary date in the past
#### data to use below
price_list = [ 0.05260218, 0.05260218,0.0,0.96769388,1.0 ] ## the prices and tax are allready normalized.
tax_list = [0.06,0.05 , 0.0 ,0.97 , 1.0]
#time_list = time_list.append(time_list) # i fear that doubling my time axis and then adding my taxes onto prices
#price_list = price_list.append(tax_list) # will be like having ten prices rather than 5 prices with a corresponding tax for each
these_dates = np.array(time_list)
prices = np.array(price_list)
prices = prices.reshape(len(prices) , 1, 1)
model = Sequential()
model.add(LSTM(10 , return_sequences = True , input_shape =(len(prices) , 1) ,input_dim=2))
model.compile(optimizer = 'adam' , loss = 'mean_squared_error')
model.fit( prices ,these_dates , batch_size = 1 , epochs =10) # right now it works for prices but i want prices and tax